diff --git a/src/commands/compile.ts b/src/commands/compile.ts index e7af69e1..06250f45 100644 --- a/src/commands/compile.ts +++ b/src/commands/compile.ts @@ -376,8 +376,8 @@ export async function compile(docs: (CurrentTextFile | CurrentBinaryFile)[], ask } return docs; }) - .catch(() => { - compileErrorMsg(); + .catch((error) => { + compileErrorMsg(error); // Always fetch server changes, even when compile failed or got cancelled return docs; }) @@ -550,7 +550,7 @@ export async function compileExplorerItems(nodes: NodeBase[]): Promise { throw new Error(`${info}Compile error`); } }) - .catch(() => compileErrorMsg()) + .catch((error) => compileErrorMsg(error)) ); } @@ -637,7 +637,7 @@ async function promptForCompile(imported: string[], api: AtelierAPI, isIsfs: boo throw new Error(`${info}Compile error`); } }) - .catch(() => compileErrorMsg()) + .catch((error) => compileErrorMsg(error)) .finally(() => { if (isIsfs) { // Refresh the files explorer to show the new files diff --git a/src/providers/FileSystemProvider/FileSystemProvider.ts b/src/providers/FileSystemProvider/FileSystemProvider.ts index 9afed7fc..aa3c320d 100644 --- a/src/providers/FileSystemProvider/FileSystemProvider.ts +++ b/src/providers/FileSystemProvider/FileSystemProvider.ts @@ -914,7 +914,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider { } data.result.content.forEach((f) => filesToUpdate.push(f.name)); }) - .catch(() => compileErrorMsg()) + .catch((error) => compileErrorMsg(error)) ); if (file && (update || filesToUpdate.includes(file.fileName))) { // This file was just written and the write may have changed its contents or the diff --git a/src/utils/index.ts b/src/utils/index.ts index e9141e51..2b84b2c6 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -63,16 +63,25 @@ export function stringifyError(error): string { return errs.length ? `AggregateError:\n- ${errs.join("\n- ")}` : ""; } return ( - error == undefined - ? "" - : error.errorText - ? error.errorText - : typeof error == "string" - ? error - : error instanceof Error - ? error.toString() - : JSON.stringify(error) - ).trim(); + ( + error == undefined + ? "" + : error.errorText + ? error.errorText + : typeof error == "string" + ? error + : error instanceof Error + ? error.toString() + : JSON.stringify(error) + ) + .trim() + // Unescape any HTML-escpaed characters + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll(""", '"') + .replaceAll("'", "'") + .replaceAll("&", "&") + ); } catch { // Need to catch errors from JSON.stringify() return ""; @@ -1017,18 +1026,12 @@ export async function replaceFile(uri: vscode.Uri, content: string | string[] | } /** Show the compilation failure error message if required. */ -export function compileErrorMsg(): void { - vscode.window - .showErrorMessage( - "Compilation failed. Check 'ObjectScript' Output channel for details.", - !vscode.window.visibleTextEditors.some((e) => e.document.languageId == outputLangId) ? "Show" : undefined, - "Dismiss" - ) - .then((action) => { - if (action == "Show") { - outputChannel.show(true); - } - }); +export function compileErrorMsg(error: any): void { + handleError( + // Don't log the generic placeholder error if that's all we have + error instanceof Error && error.message.endsWith("Compile error") ? "" : error, + "Compilaton failed." + ); } /** Return a string containing the displayable form of `uri` */