From 55da22d918175d3073d3cf40e457e6d5295b7143 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 3 Dec 2021 15:23:49 +0100 Subject: [PATCH] Remove gRPC error code from error notifications --- .../browser/contributions/burn-bootloader.ts | 8 ++++- .../browser/contributions/upload-sketch.ts | 8 ++++- .../browser/contributions/verify-sketch.ts | 8 ++++- .../src/node/core-service-impl.ts | 29 +++++++++++++++---- i18n/en.json | 9 ++++++ 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/arduino-ide-extension/src/browser/contributions/burn-bootloader.ts b/arduino-ide-extension/src/browser/contributions/burn-bootloader.ts index 1ee0dea56..4ac79792b 100644 --- a/arduino-ide-extension/src/browser/contributions/burn-bootloader.ts +++ b/arduino-ide-extension/src/browser/contributions/burn-bootloader.ts @@ -79,7 +79,13 @@ export class BurnBootloader extends SketchContribution { } ); } catch (e) { - this.messageService.error(e.toString()); + let errorMessage = ""; + if (typeof e === "string") { + errorMessage = e; + } else { + errorMessage = e.toString(); + } + this.messageService.error(errorMessage); } finally { if (this.serialConnection.isSerialOpen()) { await this.serialConnection.connect(); diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index b18861b0d..e32d0793f 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -277,7 +277,13 @@ export class UploadSketch extends SketchContribution { { timeout: 3000 } ); } catch (e) { - this.messageService.error(e.toString()); + let errorMessage = ""; + if (typeof e === "string") { + errorMessage = e; + } else { + errorMessage = e.toString(); + } + this.messageService.error(errorMessage); } finally { this.uploadInProgress = false; this.onDidChangeEmitter.fire(); diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index 2440f1a6b..898953ae8 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -127,7 +127,13 @@ export class VerifySketch extends SketchContribution { { timeout: 3000 } ); } catch (e) { - this.messageService.error(e.toString()); + let errorMessage = ""; + if (typeof e === "string") { + errorMessage = e; + } else { + errorMessage = e.toString(); + } + this.messageService.error(errorMessage); } finally { this.verifyInProgress = false; this.onDidChangeEmitter.fire(); diff --git a/arduino-ide-extension/src/node/core-service-impl.ts b/arduino-ide-extension/src/node/core-service-impl.ts index 59535662b..d3f1af59a 100644 --- a/arduino-ide-extension/src/node/core-service-impl.ts +++ b/arduino-ide-extension/src/node/core-service-impl.ts @@ -23,6 +23,7 @@ import { NotificationServiceServer } from '../common/protocol'; import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb'; import { firstToUpperCase, firstToLowerCase } from '../common/utils'; import { Port } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb'; +import { nls } from '@theia/core'; @injectable() export class CoreServiceImpl extends CoreClientAware implements CoreService { @@ -85,11 +86,16 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { chunk: '\n--------------------------\nCompilation complete.\n', }); } catch (e) { + const errorMessage = nls.localize( + 'arduino/compile/error', + 'Compilation error: {0}', + e.details + ); this.responseService.appendToOutput({ - chunk: `Compilation error: ${e.details}\n`, + chunk: `${errorMessage}}\n`, severity: 'error', }); - throw e; + throw new Error(errorMessage); } } @@ -180,11 +186,17 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { ' complete.\n', }); } catch (e) { + const errorMessage = nls.localize( + 'arduino/upload/error', + '{0} error: {1}', + firstToUpperCase(task), + e.details, + ); this.responseService.appendToOutput({ - chunk: `${firstToUpperCase(task)} error: ${e.details}\n`, + chunk: `${errorMessage}\n`, severity: 'error', }); - throw e; + throw new Error(errorMessage); } finally { this.uploading = false; } @@ -227,11 +239,16 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService { result.on('end', () => resolve()); }); } catch (e) { + const errorMessage = nls.localize( + 'arduino/burnBootloader/error', + 'Error while burning the bootloader: {0}', + e.details, + ); this.responseService.appendToOutput({ - chunk: `Error while burning the bootloader: ${e.details}\n`, + chunk: `${errorMessage}\n`, severity: 'error', }); - throw e; + throw new Error(errorMessage); } } diff --git a/i18n/en.json b/i18n/en.json index 10490de0e..4c1be82bf 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -288,6 +288,15 @@ "electron": { "couldNotSave": "Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.", "unsavedChanges": "Any unsaved changes will not be saved." + }, + "compile": { + "error": "Compilation error: {0}" + }, + "upload": { + "error": "{0} error: {1}" + }, + "burnBootloader": { + "error": "Error while burning the bootloader: {0}" } }, "theia": {