MCPcopy
hub / github.com/jvilk/BrowserFS / convertError

Function convertError

src/backend/HTML5FS.ts:62–99  ·  view source on GitHub ↗

* Converts the given DOMError into an appropriate ApiError. * @url https://developer.mozilla.org/en-US/docs/Web/API/DOMError * @hidden

(err: DOMError, p: string, expectedDir: boolean)

Source from the content-addressed store, hash-verified

60 * @hidden
61 */
62function convertError(err: DOMError, p: string, expectedDir: boolean): ApiError {
63 switch (err.name) {
64 /* The user agent failed to create a file or directory due to the existence of a file or
65 directory with the same path. */
66 case "PathExistsError":
67 return ApiError.EEXIST(p);
68 /* The operation failed because it would cause the application to exceed its storage quota. */
69 case 'QuotaExceededError':
70 return ApiError.FileError(ErrorCode.ENOSPC, p);
71 /* A required file or directory could not be found at the time an operation was processed. */
72 case 'NotFoundError':
73 return ApiError.ENOENT(p);
74 /* This is a security error code to be used in situations not covered by any other error codes.
75 - A required file was unsafe for access within a Web application
76 - Too many calls are being made on filesystem resources */
77 case 'SecurityError':
78 return ApiError.FileError(ErrorCode.EACCES, p);
79 /* The modification requested was illegal. Examples of invalid modifications include moving a
80 directory into its own child, moving a file into its parent directory without changing its name,
81 or copying a directory to a path occupied by a file. */
82 case 'InvalidModificationError':
83 return ApiError.FileError(ErrorCode.EPERM, p);
84 /* The user has attempted to look up a file or directory, but the Entry found is of the wrong type
85 [e.g. is a DirectoryEntry when the user requested a FileEntry]. */
86 case 'TypeMismatchError':
87 return ApiError.FileError(expectedDir ? ErrorCode.ENOTDIR : ErrorCode.EISDIR, p);
88 /* A path or URL supplied to the API was malformed. */
89 case "EncodingError":
90 /* An operation depended on state cached in an interface object, but that state that has changed
91 since it was read from disk. */
92 case "InvalidStateError":
93 /* The user attempted to write to a file or directory which could not be modified due to the state
94 of the underlying filesystem. */
95 case "NoModificationAllowedError":
96 default:
97 return ApiError.FileError(ErrorCode.EINVAL, p);
98 }
99}
100
101// A note about getFile and getDirectory options:
102// These methods are called at numerous places in this file, and are passed

Callers 4

syncMethod · 0.70
errorMethod · 0.70
failedToLoadMethod · 0.70
errMethod · 0.70

Calls 3

EEXISTMethod · 0.80
FileErrorMethod · 0.80
ENOENTMethod · 0.80

Tested by

no test coverage detected