Skip to content

Commit

Permalink
move the success case down
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Nov 14, 2024
1 parent f8f1e8b commit 350cb8e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions libs/filer/workspace_files_extensions_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,6 @@ func (w *workspaceFilesExtensionsClient) Delete(ctx context.Context, name string
func (w *workspaceFilesExtensionsClient) Stat(ctx context.Context, name string) (fs.FileInfo, error) {
info, err := w.wsfs.Stat(ctx, name)

// If an object is found and it is not a notebook, return the stat object. This check is done
// to avoid returning the stat for a notebook called `foo` when the user actually
// wanted to stat a file called `foo`.
//
// To stat the metadata of a notebook called `foo` in the workspace the user
// should use the name with the extension included like `foo.ipynb` or `foo.sql`.
if err == nil && info.Sys().(workspace.ObjectInfo).ObjectType != workspace.ObjectTypeNotebook {
return info, nil
}

// If a notebook is found by the workspace files client, without having stripped
// the extension, this implies that no file with the same name exists.
if err == nil && info.Sys().(workspace.ObjectInfo).ObjectType == workspace.ObjectTypeNotebook {
return nil, FileDoesNotExistError{name}
}

// If the file is not found, it might be a notebook.
if errors.As(err, &FileDoesNotExistError{}) {
stat, serr := w.getNotebookStatByNameWithExt(ctx, name)
Expand All @@ -342,7 +326,24 @@ func (w *workspaceFilesExtensionsClient) Stat(ctx context.Context, name string)
return wsfsFileInfo{ObjectInfo: stat.ObjectInfo}, nil
}

return nil, err
if err != nil {
return nil, err
}

// If an object is found and it is a notebook, return a FileDoesNotExistError.
// If a notebook is found by the workspace files client, without having stripped
// the extension, this implies that no file with the same name exists.
//
// This check is done to avoid returning the stat for a notebook called `foo`
// when the user actually wanted to stat a file called `foo`.
//
// To stat the metadata of a notebook called `foo` in the workspace the user
// should use the name with the extension included like `foo.ipynb` or `foo.sql`.
if info.Sys().(workspace.ObjectInfo).ObjectType == workspace.ObjectTypeNotebook {
return nil, FileDoesNotExistError{name}
}

return info, nil
}

// Note: The import API returns opaque internal errors for namespace clashes
Expand Down

0 comments on commit 350cb8e

Please sign in to comment.