Skip to content

Commit 4e2e6bd

Browse files
fix(Wind): Align FileSystemProviderError names with VS Code's token format
Wind's FileSystemErrorCode uses key-like values ('FileNotFound', 'FileExists'), but VS Code's toFileSystemProviderErrorCode extracts the token from error.name and switches on 'EntryNotFound', 'EntryExists', etc. Add a mapping function VsCodeErrorCodeToken to translate between the two formats. Also set this.name to the '<code> (FileSystemError)' pattern that VS Code's markAsFileSystemProviderError() expects. Remove individual name assignments from subclasses since the base class now handles naming. Without this fix, mkdirp and validateWriteFile treat missing-file/dir errors as unknown and rethrow, surfacing as unhandled rejections like 'Unable to write file .../tasks.log (Error: Failed to stat file ...)'.
1 parent 671d832 commit 4e2e6bd

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

Source/FileSystem/Error/FileSystemProviderError.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,48 @@
77

88
import { FileSystemErrorCode } from "../Type/FileSystemType.js";
99

10+
/**
11+
* Map Wind's `FileSystemErrorCode` to the exact string VS Code's enum uses.
12+
* VS Code's `toFileSystemProviderErrorCode` (`vs/platform/files/common/files.ts:863`)
13+
* extracts the token from `error.name` and switches on `'EntryNotFound'`,
14+
* `'EntryExists'`, etc. - NOT the enum key names. Our enum uses the key-like
15+
* values (`"FileNotFound"`, `"FileExists"`); translate here so the name we
16+
* emit matches what VS Code parses back.
17+
*/
18+
const VsCodeErrorCodeToken: Record<FileSystemErrorCode, string> = {
19+
[FileSystemErrorCode.FileNotFound]: "EntryNotFound",
20+
[FileSystemErrorCode.FileExists]: "EntryExists",
21+
[FileSystemErrorCode.NoPermissions]: "NoPermissions",
22+
[FileSystemErrorCode.InvalidPath]: "Unknown",
23+
[FileSystemErrorCode.NotSupported]: "Unknown",
24+
[FileSystemErrorCode.Unknown]: "Unknown",
25+
};
26+
1027
// ============================================================================
1128
// Error Base Class
1229
// ============================================================================
1330

1431
/**
15-
* Base error class for file system provider operations
32+
* Base error class for file system provider operations.
33+
*
34+
* `name` MUST follow the `"<code> (FileSystemError)"` convention so that
35+
* VS Code's `toFileSystemProviderErrorCode` (in `vs/platform/files/common/files.ts`)
36+
* can recognise the error without requiring `instanceof FileSystemProviderError`
37+
* - Wind's class is a SEPARATE class from VS Code's (different module), so
38+
* the instanceof check fails and VS Code falls back to regex-matching `error.name`.
39+
* This name shape is VS Code's `markAsFileSystemProviderError()` contract.
40+
*
41+
* Without this, `mkdirp` and `validateWriteFile` treat missing-file/dir errors
42+
* as unknown and rethrow, surfacing as unhandled rejections like
43+
* `Unable to write file '.../output_<ts>/tasks.log' (Error: Failed to stat file ...)`.
1644
*/
1745
export class FileSystemProviderError extends Error {
1846
_tag: string;
1947
readonly code: FileSystemErrorCode;
2048

2149
constructor(message: string, code: FileSystemErrorCode, cause?: unknown) {
2250
super(message, cause ? { cause } : undefined);
23-
this.name = "FileSystemProviderError";
51+
this.name = `${VsCodeErrorCodeToken[code] ?? "Unknown"} (FileSystemError)`;
2452
this._tag = "FileSystemProviderError";
2553
this.code = code;
2654
}
@@ -36,7 +64,6 @@ export class FileNotFoundError extends FileSystemProviderError {
3664
FileSystemErrorCode.FileNotFound,
3765
cause,
3866
);
39-
this.name = "FileNotFoundError";
4067
this._tag = "FileNotFoundError";
4168
}
4269
}
@@ -51,7 +78,6 @@ export class FileExistsError extends FileSystemProviderError {
5178
FileSystemErrorCode.FileExists,
5279
cause,
5380
);
54-
this.name = "FileExistsError";
5581
this._tag = "FileExistsError";
5682
}
5783
}
@@ -66,7 +92,6 @@ export class PermissionError extends FileSystemProviderError {
6692
FileSystemErrorCode.NoPermissions,
6793
cause,
6894
);
69-
this.name = "PermissionError";
7095
this._tag = "PermissionError";
7196
}
7297
}
@@ -77,7 +102,6 @@ export class PermissionError extends FileSystemProviderError {
77102
export class InvalidPathError extends FileSystemProviderError {
78103
constructor(path: string, cause?: unknown) {
79104
super(`Invalid path: ${path}`, FileSystemErrorCode.InvalidPath, cause);
80-
this.name = "InvalidPathError";
81105
this._tag = "InvalidPathError";
82106
}
83107
}
@@ -92,7 +116,6 @@ export class NotSupportedError extends FileSystemProviderError {
92116
FileSystemErrorCode.NotSupported,
93117
cause,
94118
);
95-
this.name = "NotSupportedError";
96119
this._tag = "NotSupportedError";
97120
}
98121
}
@@ -107,7 +130,6 @@ export class UnknownFileSystemError extends FileSystemProviderError {
107130
FileSystemErrorCode.Unknown,
108131
cause,
109132
);
110-
this.name = "UnknownFileSystemError";
111133
this._tag = "UnknownFileSystemError";
112134
}
113135
}

Target/FileSystem/Error/FileSystemProviderError.js

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)