file_errors 1.0.2 copy "file_errors: ^1.0.2" to clipboard
file_errors: ^1.0.2 copied to clipboard

outdated

Cross-platform extensions that help determine the cause of a caught FileSystemException.

file_errors #

Cross-platform extensions that help determine the cause of a caught FileSystemException.

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.

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

  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');
    }
  }

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.

0
likes
0
pub points
0%
popularity

Publisher

verified publisherrevercode.com

Cross-platform extensions that help determine the cause of a caught FileSystemException.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

errno

More

Packages that depend on file_errors