Skip to content

Commit

Permalink
fix: error handling in OPFSFileSystemProvider (#14790)
Browse files Browse the repository at this point in the history
Ensure proper "file not found" and "file not a directory" errors are
thrown in OPFSFilesystemProvider. Fixes an issue where new directories
could not be created via the FileService.
  • Loading branch information
robertjndw authored Jan 29, 2025
1 parent cd6cddb commit 22d1898
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ export class OPFSFileSystemProvider implements FileSystemProviderWithFileReadWri
}

throw createFileSystemProviderError('Unknown file handle error', FileSystemProviderErrorCode.Unknown);

} catch (error) {
throw createFileSystemProviderError(`Error while accessing resource ${resource.toString()}`, FileSystemProviderErrorCode.Unknown);
throw toFileSystemProviderError(error);
}
}

Expand Down Expand Up @@ -262,7 +261,7 @@ async function recursiveFileSystemHandle(handle: FileSystemHandle, pathParts: st
}
// If there are parts left, the handle must be a directory
if (handle.kind !== 'directory') {
throw FileSystemProviderErrorCode.FileNotADirectory;
throw createFileSystemProviderError('Not a directory', FileSystemProviderErrorCode.FileNotADirectory);
}
const dirHandle = handle as FileSystemDirectoryHandle;
// We need to create it and thus we need to stop early to create the file or directory
Expand All @@ -289,7 +288,7 @@ async function recursiveFileSystemHandle(handle: FileSystemHandle, pathParts: st
return recursiveFileSystemHandle(newHandle, pathParts, options);
}

throw FileSystemProviderErrorCode.FileNotFound;
throw createFileSystemProviderError('File not found', FileSystemProviderErrorCode.FileNotFound);
}

// Function to copy directory contents recursively
Expand Down

0 comments on commit 22d1898

Please sign in to comment.