-
Notifications
You must be signed in to change notification settings - Fork 121
Unexport errors returned by the filer package #4156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pietern
wants to merge
4
commits into
main
Choose a base branch
from
unexport-filer-errors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package filer | ||
|
|
||
| import "io/fs" | ||
|
|
||
| // fileAlreadyExistsError is returned when attempting to write a file at a path | ||
| // that already exists, without using the OverwriteIfExists WriteMode flag. | ||
| type fileAlreadyExistsError struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err fileAlreadyExistsError) Error() string { | ||
| return "file already exists: " + err.path | ||
| } | ||
|
|
||
| func (err fileAlreadyExistsError) Is(other error) bool { | ||
| return other == fs.ErrExist | ||
| } | ||
|
|
||
| // fileDoesNotExistError is returned when attempting to read, delete, or stat | ||
| // a file that does not exist. It is also returned by the workspace files | ||
| // extensions client when a notebook exists at a path but a file was expected. | ||
| type fileDoesNotExistError struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err fileDoesNotExistError) Is(other error) bool { | ||
| return other == fs.ErrNotExist | ||
| } | ||
|
|
||
| func (err fileDoesNotExistError) Error() string { | ||
| return "file does not exist: " + err.path | ||
| } | ||
|
|
||
| // noSuchDirectoryError is returned when attempting to write a file to a path | ||
| // whose parent directory does not exist (without CreateParentDirectories mode), | ||
| // or when attempting to read a directory that does not exist. | ||
| type noSuchDirectoryError struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err noSuchDirectoryError) Error() string { | ||
| return "no such directory: " + err.path | ||
| } | ||
|
|
||
| func (err noSuchDirectoryError) Is(other error) bool { | ||
| return other == fs.ErrNotExist | ||
| } | ||
|
|
||
| // notADirectory is returned when attempting to read a directory (ReadDir) | ||
| // but the path points to a file instead of a directory. | ||
| type notADirectory struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err notADirectory) Error() string { | ||
| return "not a directory: " + err.path | ||
| } | ||
|
|
||
| func (err notADirectory) Is(other error) bool { | ||
| return other == fs.ErrInvalid | ||
| } | ||
|
|
||
| // notAFile is returned when attempting to read a file but the path points | ||
| // to a directory instead of a file. | ||
| type notAFile struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err notAFile) Error() string { | ||
| return "not a file: " + err.path | ||
| } | ||
|
|
||
| func (err notAFile) Is(other error) bool { | ||
| return other == fs.ErrInvalid | ||
| } | ||
|
|
||
| // directoryNotEmptyError is returned when attempting to delete a directory | ||
| // that contains files or subdirectories, without using the DeleteRecursively | ||
| // DeleteMode flag. | ||
| type directoryNotEmptyError struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err directoryNotEmptyError) Error() string { | ||
| return "directory not empty: " + err.path | ||
| } | ||
|
|
||
| func (err directoryNotEmptyError) Is(other error) bool { | ||
| return other == fs.ErrInvalid | ||
| } | ||
|
|
||
| // cannotDeleteRootError is returned when attempting to delete the root path | ||
| // of the filer. Deleting the root is not allowed as it would break subsequent | ||
| // file operations. | ||
| type cannotDeleteRootError struct{} | ||
|
|
||
| func (err cannotDeleteRootError) Error() string { | ||
| return "unable to delete filer root" | ||
| } | ||
|
|
||
| func (err cannotDeleteRootError) Is(other error) bool { | ||
| return other == fs.ErrInvalid | ||
| } | ||
|
|
||
| // permissionError is returned when access is denied to a path, for example | ||
| // when attempting to create a directory but lacking write permissions. | ||
| type permissionError struct { | ||
| path string | ||
| } | ||
|
|
||
| func (err permissionError) Error() string { | ||
| return "access denied: " + err.path | ||
| } | ||
|
|
||
| func (err permissionError) Is(other error) bool { | ||
| return other == fs.ErrPermission | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to this PR, but is fs.ErrInvalid a correct error to use? The docs say "invalid argument", implies bad arguments passed to the function, not an issue with remote object being a wrong type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The
fspackage doesn't have a better alternative. But if we need one, we could add a few constants tolibs/filerfor more specific checks.