Skip to content

Commit dd6436a

Browse files
committed
use FileSystemError
1 parent f4eecde commit dd6436a

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
291291

292292
public async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> {
293293
if (uri.path.includes(".vscode/") || uri.path.endsWith(".vscode")) {
294-
throw "Cannot read the /.vscode directory";
294+
throw new vscode.FileSystemError("Cannot read the /.vscode directory");
295295
}
296296
const parent = await this._lookupAsDirectory(uri);
297297
const api = new AtelierAPI(uri);
@@ -406,7 +406,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
406406
}
407407

408408
public createDirectory(uri: vscode.Uri): void | Thenable<void> {
409-
uri = redirectDotvscodeRoot(uri, "Server does not have a /_vscode web application");
409+
uri = redirectDotvscodeRoot(uri, new vscode.FileSystemError("Server does not have a /_vscode web application"));
410410
const basename = path.posix.basename(uri.path);
411411
const dirname = uri.with({ path: path.posix.dirname(uri.path) });
412412
return this._lookupAsDirectory(dirname).then((parent) => {
@@ -435,9 +435,9 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
435435
overwrite: boolean;
436436
}
437437
): void | Thenable<void> {
438-
uri = redirectDotvscodeRoot(uri, "Server does not have a /_vscode web application");
438+
uri = redirectDotvscodeRoot(uri, new vscode.FileSystemError("Server does not have a /_vscode web application"));
439439
if (uri.path.startsWith("/.")) {
440-
throw "dot-folders are not supported by server";
440+
throw new vscode.FileSystemError("dot-folders are not supported by server");
441441
}
442442
const csp = isCSP(uri);
443443
const fileName = isfsDocumentName(uri, csp);
@@ -462,10 +462,12 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
462462
[, clsname] = match;
463463
}
464464
if (clsname == "") {
465-
throw new Error("Cannot save a malformed class");
465+
throw new vscode.FileSystemError("Cannot save a malformed class");
466466
}
467467
if (fileName.slice(0, -4) != clsname) {
468-
throw new Error("Cannot save an isfs class where the class name and file name do not match");
468+
throw new vscode.FileSystemError(
469+
"Cannot save an isfs class where the class name and file name do not match"
470+
);
469471
}
470472
if (openLowCodeEditors.has(uri.toString())) {
471473
// This class is open in a low-code editor, so any
@@ -474,7 +476,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
474476
}
475477
// Check if the class is deployed
476478
if (await isClassDeployed(fileName, api)) {
477-
throw new Error("Cannot overwrite a deployed class");
479+
throw new vscode.FileSystemError("Cannot overwrite a deployed class");
478480
}
479481
}
480482
const contentBuffer = Buffer.from(content);
@@ -505,7 +507,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
505507
.catch((error) => {
506508
// Throw all failures
507509
const errorStr = stringifyError(error);
508-
throw errorStr ? errorStr : vscode.FileSystemError.Unavailable(uri);
510+
throw errorStr ? new vscode.FileSystemError(errorStr) : vscode.FileSystemError.Unavailable(uri);
509511
});
510512
},
511513
(error) => {
@@ -529,7 +531,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
529531
.catch((error) => {
530532
// Throw all failures
531533
const errorStr = stringifyError(error);
532-
throw errorStr ? errorStr : vscode.FileSystemError.Unavailable(uri);
534+
throw errorStr ? new vscode.FileSystemError(errorStr) : vscode.FileSystemError.Unavailable(uri);
533535
})
534536
.then((data) => {
535537
// New file has been written
@@ -724,13 +726,13 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
724726

725727
public async rename(oldUri: vscode.Uri, newUri: vscode.Uri, options: { overwrite: boolean }): Promise<void> {
726728
if (!oldUri.path.split("/").pop().includes(".")) {
727-
throw "Cannot rename a package/folder";
729+
throw new vscode.FileSystemError("Cannot rename a package/folder");
728730
}
729731
if (oldUri.path.split(".").pop().toLowerCase() != newUri.path.split(".").pop().toLowerCase()) {
730-
throw "Cannot change a file's extension during rename";
732+
throw new vscode.FileSystemError("Cannot change a file's extension during rename");
731733
}
732734
if (vscode.workspace.getWorkspaceFolder(oldUri) != vscode.workspace.getWorkspaceFolder(newUri)) {
733-
throw "Cannot rename a file across workspace folders";
735+
throw new vscode.FileSystemError("Cannot rename a file across workspace folders");
734736
}
735737
// Check if the destination exists
736738
let newFileStat: vscode.FileStat;
@@ -774,7 +776,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
774776
.catch((error) => {
775777
// Throw all failures
776778
const errorStr = stringifyError(error);
777-
throw errorStr ? errorStr : vscode.FileSystemError.Unavailable(newUri);
779+
throw errorStr ? new vscode.FileSystemError(errorStr) : vscode.FileSystemError.Unavailable(newUri);
778780
})
779781
.then(async (response) => {
780782
// New file has been written
@@ -807,7 +809,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
807809
*/
808810
public async compile(uri: vscode.Uri, file?: File, update?: boolean): Promise<void> {
809811
if (!uri || uri.scheme != FILESYSTEM_SCHEMA) return;
810-
uri = redirectDotvscodeRoot(uri, "Server does not have a /_vscode web application");
812+
uri = redirectDotvscodeRoot(uri, new vscode.FileSystemError("Server does not have a /_vscode web application"));
811813
const compileList: string[] = [];
812814
try {
813815
const entry = file || (await this._lookup(uri, true));
@@ -960,7 +962,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
960962
private async _lookupAsFile(uri: vscode.Uri, cachedFile?: File): Promise<File> {
961963
uri = redirectDotvscodeRoot(uri, vscode.FileSystemError.FileNotFound(uri));
962964
if (uri.path.startsWith("/.")) {
963-
throw "dot-folders are not supported by server";
965+
throw new vscode.FileSystemError("dot-folders are not supported by server");
964966
}
965967
const csp = isCSP(uri);
966968
const name = path.basename(uri.path);
@@ -992,13 +994,13 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
992994
throw error?.statusCode == 404
993995
? vscode.FileSystemError.FileNotFound(uri)
994996
: errorStr
995-
? errorStr
997+
? new vscode.FileSystemError(errorStr)
996998
: vscode.FileSystemError.Unavailable(uri);
997999
});
9981000
}
9991001

10001002
private async _lookupParentDirectory(uri: vscode.Uri): Promise<Directory> {
1001-
uri = redirectDotvscodeRoot(uri, "Server does not have a /_vscode web application");
1003+
uri = redirectDotvscodeRoot(uri, new vscode.FileSystemError("Server does not have a /_vscode web application"));
10021004
return this._lookupAsDirectory(uri.with({ path: path.posix.dirname(uri.path) }));
10031005
}
10041006

src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ export async function addWsServerRootFolderData(wsFolders: readonly vscode.Works
650650
* @throws if `ns` queryparam is missing but required, or if redirection
651651
* is required but not supported by the server and `err` was passed.
652652
*/
653-
export function redirectDotvscodeRoot(uri: vscode.Uri, err?: any): vscode.Uri {
653+
export function redirectDotvscodeRoot(uri: vscode.Uri, err?: vscode.FileSystemError): vscode.Uri {
654654
if (notIsfs(uri)) return;
655655
const dotMatch = uri.path.match(/^(.*)\/\.vscode(\/.*)?$/);
656656
if (dotMatch) {

0 commit comments

Comments
 (0)