Skip to content

Commit 22d1898

Browse files
authored
fix: error handling in OPFSFileSystemProvider (eclipse-theia#14790)
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.
1 parent cd6cddb commit 22d1898

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

packages/filesystem/src/browser-only/opfs-filesystem-provider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ export class OPFSFileSystemProvider implements FileSystemProviderWithFileReadWri
103103
}
104104

105105
throw createFileSystemProviderError('Unknown file handle error', FileSystemProviderErrorCode.Unknown);
106-
107106
} catch (error) {
108-
throw createFileSystemProviderError(`Error while accessing resource ${resource.toString()}`, FileSystemProviderErrorCode.Unknown);
107+
throw toFileSystemProviderError(error);
109108
}
110109
}
111110

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

292-
throw FileSystemProviderErrorCode.FileNotFound;
291+
throw createFileSystemProviderError('File not found', FileSystemProviderErrorCode.FileNotFound);
293292
}
294293

295294
// Function to copy directory contents recursively

0 commit comments

Comments
 (0)