-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Refactor error types #67
Conversation
src/fs.rs
Outdated
@@ -1254,23 +1254,19 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> { | |||
let path_slice = path.as_ref().as_bytes(); | |||
for i in 0..path_slice.len() { | |||
if path_slice[i] == b'/' { | |||
let dir = PathBuf::try_from(&path_slice[..i])?; | |||
let dir = PathBuf::try_from(&path_slice[..i]).map_err(|_| ErrorKind::Io)?; |
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.
Maybe this should be ErrorKind::NameTooLong
?
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.
I did not want to change the existing behavior, but I think this cannot fail anyway. If we would have a proper split
method in Path
, we could get rid of the error entirely.
If the constants on |
That's a good point. We can re-introduce ErrorKind in the future if we ever need it. |
Okay. Then I would change the constant names to match the old variant names, e. g. |
To make it easier to add support for new error codes without breaking compatibility, this patch replaces the Error enum with a struct and associated constants. As a part of this change, it also enforces that Error is not used for return values indicating success, i. e. only for negative return values.
This PR splits the
Error
enum into anError
struct and a non-exhaustiveErrorKind
enum. This makes it possible to add support for new error codes without breaking compatibility. The PR also removes the edge case ofError
instances for non-negative return values indicating success.See this issue for context and discussion:
Contrary to the suggestion in #55 (comment), this implementation does not provide a
fn error(&self) -> Option<ErrorKind>
onError
. It would again cause the problem that users could rely on this method returningNone
for some currently unsupported error. Instead,Error
implementsPartialEq<ErrorKind>
so that users can compare it directly against known error kinds. The only limitation is that it is not possible tomatch
on the error kind, but I don’t see a need for that anyway.