Skip to content
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

Improve error ergonomics for end users #34

Merged
merged 4 commits into from
Jul 25, 2022

Conversation

Technohacker
Copy link
Contributor

Allows end users of VFS to match against ErrorKind directly without having
to drill down through the WithContext variant

Also offers a normalization for I/O errors to ensure the corresponding
VFS Error kind is used rather than a generic I/O Error

Fixes #33

@Technohacker
Copy link
Contributor Author

Marked as a draft due to the test suite being broken. There's no longer a From<io::Error> impl for VfsError since it also needs the path where the error occured. Hence each call site needs to map_err to VfsError manually. Any other possible solutions?

@manuel-woelker
Copy link
Owner

Hi, sorry for the late reply.

It might be possible to implement From<io::Error>, leaving the path blank initially and have it be filled in not by the FS impl, but by the VFS infrastructure. This would mean that the path is the VFS path not the physical filesystem path. This would make it easier on FS implementors, and would keep the error paths the same across different FS implementations.

@Technohacker
Copy link
Contributor Author

Ah that's a good idea, I'll try that out

Allows end users of VFS to match against ErrorKind directly without having
to drill down through the WithContext variant

Also offers a normalization for I/O errors to ensure the corresponding
VFS Error kind is used rather than a generic I/O Error
@Technohacker
Copy link
Contributor Author

Apologies for the delay, couldn't get back to this earlier 😅

Had to tweak my error message output to match the existing format somewhat, and some of the test cases to match the details (thanks for the error message test suite!), so that'd probably require some review

VfsError now keeps a placeholder path and context if none was provided explicitly to make error handling from the implementations easier, but this means the core VFS abstraction has to manually ensure a path is filled. Maybe if we have two error types (one for the concrete impl, another for VFS itself) this could be checked at compile-time

Would love to get further review on this :)

@manuel-woelker
Copy link
Owner

Great, thanks for the update, I'll try to get a look at the changes tomorrow.

let kind = match kind {
VfsErrorKind::IoError(io) => match io.kind() {
io::ErrorKind::NotFound => VfsErrorKind::FileNotFound,
// TODO: If MSRV changes to 1.53, enable this. Alternatively,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(accessible(::path::to::thing))] might be an option here in the future

rust-lang/rust#64797

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's neat! However I don't think those would be usable for 1.40 since these would be newer additions to the language right?

IoError(std::io::Error),
pub struct VfsError {
/// The path this error was encountered in
path: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether it might make sense to have this actually be a Vec<String>.
This would handle multiple paths better (e.g. for copy operations).

What are your thoughts on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd be able to pinpoint which part of the copy operation failed, whether it was reading the source or writing to the destination. I wonder if we have enough information for this?

@manuel-woelker
Copy link
Owner

Hi again, I just reviewed the PR and it looks good to me! 👍 Anything else you want to add or change, or can we go ahead and merge?

@Technohacker
Copy link
Contributor Author

Thanks! Just a few things off the top of my head :)

Splitting the error type into a VFS abstraction error and an FS implementation error could be useful if we want to avoid any chance of forgetting to fill the path in VFS, though that could require a little boilerplate

With the current design, is VFS in charge of filling the cause for the error or is it upto the implementations?

@manuel-woelker
Copy link
Owner

Let's start with only a single error type for now, and address the issue of filling in the path if it turns out to be an issue.

Regarding filling the cause, I'd say both. If an implementation has additional information regarding a cause, it can add that and if the VFS wants to wrap the error as cause it can do so as well.

@Technohacker
Copy link
Contributor Author

Alright in that case for now, this should be good :)
Pretty sure this will be a breaking change, so that's something to note 😅

@Technohacker Technohacker marked this pull request as ready for review July 22, 2022 17:09
@manuel-woelker manuel-woelker merged commit 5786282 into manuel-woelker:master Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VfsError does not have an easy way to programmatically match against Error Variants
2 participants