Skip to content

Directory.resolveSymbolicLinksSync could throw more specific exception #61946

@davidmorgan

Description

@davidmorgan

It throws FileSystemException even when there is a more specific type that would fit if it failed due to "not found" or "access denied".

Here is a code snippet that converts to a better exception type.

try {
  directory.resolveSymbolicLinksSync());
} on FileSystemException catch (e, s) {
  if (e.message.contains('Cannot resolve symbolic links')) {
    if (e.osError?.errorCode == 2) {
      throw Error.throwWithStackTrace(
        PathNotFoundException(directory.path, e.osError!), s);
    } else if (e.osError?.errorCode == 5) {
      throw Error.throwWithStackTrace(
        PathAccessException(directory.path, e.osError!), s);
    }
}

Discovered because of package:watcher code that tries to ignore specific subtypes of FileSystemException.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-iotriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions