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

Provide cleaner way to detect file not found and directory not found errors #12461

Closed
munificent opened this issue Aug 14, 2013 · 16 comments
Closed
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@munificent
Copy link
Member

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.

@sethladd
Copy link
Contributor

Removed Type-Defect label.
Added Type-Enhancement, Area-IO, Triaged labels.

@andersjohnsen
Copy link

The plan is as follows:

  1. Remove DirectoryException and LinkException, so we only use FileException.
  2. Roll out specific FileExceptions, such as NotFoundException, PermissionException, etc. The list is not decided upon yet.

We're landing 1) ASAP, as that's the only breaking part of this change.


Set owner to @skabet.
Added Accepted label.

@munificent
Copy link
Member Author

SGTM, though I would probably prefer IOException over FileException since it will be confusing to get a FileException from a directory method.

@andersjohnsen
Copy link

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?

@munificent
Copy link
Member Author

I would just like to group file-system related exceptions under one item, thus why I kept FileException.

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.

I suppose the right name would be FileSystemException, but it's rather long.

Yeah, that's pretty painful, especially given that this is one of the most common types to actually intentionally catch.

@andersjohnsen
Copy link

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.

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.

@munificent
Copy link
Member Author

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.

@sgjesse
Copy link
Contributor

sgjesse commented Oct 28, 2013

Added this to the Later milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@kevmoo
Copy link
Member

kevmoo commented May 14, 2014

Removed Area-IO label.
Added Library-IO, Area-Library labels.

@andersjohnsen
Copy link

Removed the owner.
Added Triaged label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@munificent munificent added Type-Enhancement library-io area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@Keithcat1
Copy link

I'm also a little interested in this. Languages like Python will raise a FileNotFound error and not just an IoError.
I guess this will have to be changed in Dart 3, unless it won't break compatibility?

@brianquinlan
Copy link
Contributor

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...

I agree with the issue overall but do you have a repro where a non-existent file generates a errorCode or 3 on Windows?

I just tested with File.openRead and get errorCode 2.

@brianquinlan brianquinlan self-assigned this Nov 2, 2022
@brianquinlan
Copy link
Contributor

PR in progress here: https://dart-review.googlesource.com/c/sdk/+/267280

copybara-service bot pushed a commit that referenced this issue Nov 8, 2022
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>
@brianquinlan
Copy link
Contributor

Fixed in b75f8aa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

8 participants