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
Provide cleaner way to detect file not found and directory not found errors #12461
Comments
Removed Type-Defect label. |
The plan is as follows:
We're landing 1) ASAP, as that's the only breaking part of this change. Set owner to @skabet. |
SGTM, though I would probably prefer IOException over FileException since it will be confusing to get a FileException from a directory method. |
IOException is already there. I would just like to group file-system related exceptions under one item, thus why I kept FileException. I suppose the right name would be FileSystemException, but it's rather long. Bob, what do you think? |
Do you have use cases where a user might want to catch FileException and not also catch other non-File IOExceptions? If not, I would just get rid of FileException.
Yeah, that's pretty painful, especially given that this is one of the most common types to actually intentionally catch. |
If we create a hierarchy, I want the user to be able to catch all, and only, file-system exceptions. But as you say, this would be the only scenario where you would have to spell out FileSystemException - normally people can just to IOException or e.g. NotFoundException. |
I'm not sure if I have a good intuition of what's a FileSystemException and what's an IOException. I worry that users catching the first might actually want to catch the second and not realize it. If you think it's a useful distinction, then go for it, but my inclination is to keep exception hierarchies pretty shallow. |
Added this to the Later milestone. |
Removed Area-IO label. |
Removed the owner. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
I'm also a little interested in this. Languages like Python will raise a FileNotFound error and not just an IoError. |
I agree with the issue overall but do you have a repro where a non-existent file generates a I just tested with |
PR in progress here: https://dart-review.googlesource.com/c/sdk/+/267280 |
Thrown by when an operation fails because a file is not found. TEST=updated unit tests Issue: #12461 Change-Id: I2e6e3986f92d5bf9f3922f4e2c6bbba67cc102bc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/267280 Reviewed-by: Lasse Nielsen <lrn@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Brian Quinlan <bquinlan@google.com>
Fixed in b75f8aa |
If you try to perform an IO operation on a non-existent entity, you'll get either a FileException or a DirectoryException whose OSError has an errorCode of 2 on Mac/Linux and 3 on Windows. This makes handling a file-not-found error at runtime awkward.
How about a custom NotFoundException type?
Also, what's the difference between DirectoryException and FileException? They seem to have the same state.
The text was updated successfully, but these errors were encountered: