From 26441dca34647bef422c8ee4681a10bc32973440 Mon Sep 17 00:00:00 2001 From: Heliozoa Date: Wed, 25 Sep 2024 14:21:10 +0300 Subject: [PATCH] Improve error messages and special case macOS compatibility error --- src/api/tmc.ts | 9 +++++++++ src/panels/TmcPanel.ts | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/api/tmc.ts b/src/api/tmc.ts index 40e450a2..8c9b4dc4 100644 --- a/src/api/tmc.ts +++ b/src/api/tmc.ts @@ -1053,6 +1053,15 @@ export default class TMC { if (timeout) { clearTimeout(timeout); } + if ("errno" in error) { + // check for macos error code -88 + // which indicates an architecture mismatch + if (error.errno === -88) { + error.message = `A compatibility error was detected. +If you're on macOS: Try installing Rosetta by running \`softwareupdate --install-rosetta\` in the terminal. (See https://support.apple.com/en-us/102527). +${error.message}`; + } + } reject(error); }); cprocess.stderr.on("data", (chunk) => { diff --git a/src/panels/TmcPanel.ts b/src/panels/TmcPanel.ts index 10e66a7f..5d5c74db 100644 --- a/src/panels/TmcPanel.ts +++ b/src/panels/TmcPanel.ts @@ -401,7 +401,8 @@ export class TmcPanel { const organizations = await actionContext.tmc.getOrganizations(); if (organizations.err) { actionContext.dialog.errorNotification( - `Failed to open panel: ${organizations.err}`, + "Failed to open panel.", + organizations.val, ); return; } @@ -423,7 +424,8 @@ export class TmcPanel { const courses = await actionContext.tmc.getCourses(organization.slug); if (courses.err) { actionContext.dialog.errorNotification( - `Failed to open panel: ${courses.err}`, + "Failed to open panel.", + courses.val, ); return; } @@ -444,7 +446,8 @@ export class TmcPanel { const organizations = await actionContext.tmc.getOrganizations(); if (organizations.err) { actionContext.dialog.errorNotification( - `Failed to open panel: ${organizations.err}`, + "Failed to open panel.", + organizations.val, ); return; } @@ -590,8 +593,8 @@ export class TmcPanel { await actionContext.tmc.listLocalCourseExercises(message.courseName); if (localCourseExercises.err) { actionContext.dialog.errorNotification( - `Error trying to list local exercises while opening selected exercises. \ - ${localCourseExercises.val}`, + "Error trying to list local exercises while opening selected exercises.", + localCourseExercises.val, ); return; } @@ -643,7 +646,7 @@ export class TmcPanel { const updateResult = await updateCourse(actionContext, courseId); if (updateResult.err) { actionContext.dialog.errorNotification( - `Failed to update course: ${updateResult.val.message}`, + "Failed to update course.", updateResult.val, ); } @@ -675,7 +678,8 @@ export class TmcPanel { ); if (result.err) { actionContext.dialog.errorNotification( - `Failed to add new course: ${result.val.message}`, + "Failed to add new course.", + result.val, ); } postMessageToWebview(webview, { @@ -736,7 +740,7 @@ export class TmcPanel { ); if (pasteResult.err) { actionContext.dialog.errorNotification( - `Failed to send to TMC Paste: ${pasteResult.val.message}.`, + "Failed to send to TMC Paste.", pasteResult.val, ); TmcPanel.postMessage({