https://github.com/rtmigo/file_errors
Cross-platform extensions that help determine the cause of a caught FileSystemException
https://github.com/rtmigo/file_errors
android dart darwin directories enoent errno error-codes errors exceptions filesystem filesystemexception flutter ios linux macos os posix windows
Last synced: 3 months ago
JSON representation
Cross-platform extensions that help determine the cause of a caught FileSystemException
- Host: GitHub
- URL: https://github.com/rtmigo/file_errors
- Owner: rtmigo
- License: mit
- Created: 2021-03-22T17:45:42.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-29T09:48:37.000Z (almost 5 years ago)
- Last Synced: 2025-03-14T23:11:53.262Z (10 months ago)
- Topics: android, dart, darwin, directories, enoent, errno, error-codes, errors, exceptions, filesystem, filesystemexception, flutter, ios, linux, macos, os, posix, windows
- Language: Dart
- Homepage: https://pub.dev/packages/file_errors
- Size: 56.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dev/packages/file_errors)

[](https://github.com/rtmigo/file_errors/actions)

# [file_errors](https://github.com/rtmigo/file_errors)
**Cross-platform** extensions that help determine the **cause** of
a caught `FileSystemException`:
- `FileSystemException.isNoSuchFileOrDirectory`
- `FileSystemException.isDirectoryNotEmpty`
## isNoSuchFileOrDirectory
Occurs when:
- Trying to read a non-existent file in an existing directory
- Trying to read or write a file in a non-existent directory
- Trying to non-recursively create a file in a non-existent directory
- Trying to list a non-existent directory
``` dart
try {
print(File('maybe.txt').readAsStringSync());
} on FileSystemException catch (exc) {
// using property extension added by the library
if (exc.isNoSuchFileOrDirectory) {
print('It does not exist!');
}
else {
print('Unknown error: $exc');
}
}
```
## isDirectoryNotEmpty
Occurs when you try to non-recursively delete a directory but it contains files.
``` dart
try {
Directory('/path/to/useless').deleteSync();
} on FileSystemException catch (exc) {
// using property extension added by the library
if (exc.isDirectoryNotEmpty) {
print('It is not empty!');
}
else {
print('Unknown error: $exc');
}
}
```
# Compatibility
The extensions were unit-tested on **Linux**, **Windows** and **MacOS**.
Mobile systems such as **Android** and **iOS** have the same kernels
as their desktop relatives. So their error codes are the same.
# Under the hood
This library interprets the `OSError.errorCode` values depending on the
current platform. It's two different error codes for `isNoSuchFileOrDirectory`
and three different error codes for `isDirectoryNotEmpty`.