-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Problem Statement
There are times in code when you catch an IOException and want to perform conditional logic based on the osError.errorCode within the exception. However, for any given semantic error code (e.g. EISDIR), its value may differ on various platforms. Complicating the problem is that the different platforms have disjoint sets of semantic errno values.
Proposed Solution
If dart:io exposed the set of semantic errno values that is common to all platforms, it would solve the 90% use case. I propose we create an ErrorCodes class with static const int values for this set of errno values.
Looking at the errno values from Linux, Mac OS, and Windows, it looks like the common set would yield the following: https://gist.github.com/tvolkert/e59f531df15ee54edb71c9d2fba6fe71
Alternatives Considered
- We could provide these values as an enum, but we want developers to be able to compare the
IOException.osError.errorCodeint value against these values, so an enum doesn't fit the use case as well as static constants. - We could provide all errno values for all platforms (rather than just exposing the common set and abstracting away the platform), but that seems gratuitous and not tailored towards solving a real problem.
- We could do nothing and let individual libraries worry about this, but given that we already expose the
OSErrorand itserrorCode, it seems like we should provide something like this indart:ioitself.