From 114da8f4950a05fae3eebdfa52e39f23ee878f3b Mon Sep 17 00:00:00 2001 From: Wenyi Luo Date: Wed, 13 Jan 2021 17:21:48 +0800 Subject: [PATCH 1/3] stringify error in local publish --- extensions/localPublish/src/index.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/extensions/localPublish/src/index.ts b/extensions/localPublish/src/index.ts index 7e01769c2c..569081f465 100644 --- a/extensions/localPublish/src/index.ts +++ b/extensions/localPublish/src/index.ts @@ -16,7 +16,6 @@ import { DialogSetting, PublishPlugin, IExtensionRegistration } from '@botframew import killPort from 'kill-port'; import map from 'lodash/map'; -import range from 'lodash/range'; import * as tcpPortUsed from 'tcp-port-used'; const stat = promisify(fs.stat); @@ -52,6 +51,17 @@ const isLocalhostUrl = (matchUrl: string) => { const isSkillHostUpdateRequired = (skillHostEndpoint?: string) => { return !skillHostEndpoint || isLocalhostUrl(skillHostEndpoint); }; + +const stringifyError = (error: any): string => { + if (error instanceof Error) { + return `${error.name} - ${error.message}`; + } else if (typeof error === 'object') { + return JSON.stringify(error, Object.getOwnPropertyNames(error)); + } else { + return error; + } +} + class LocalPublisher implements PublishPlugin { public name = 'localpublish'; public description = 'Publish bot to local runtime'; @@ -114,7 +124,7 @@ class LocalPublisher implements PublishPlugin { this.setBotStatus(botId, { status: 500, result: { - message: error.message, + message: stringifyError(error), }, }); } @@ -149,7 +159,7 @@ class LocalPublisher implements PublishPlugin { return { status: 500, result: { - message: error, + message: stringifyError(error), }, }; } @@ -279,7 +289,7 @@ class LocalPublisher implements PublishPlugin { } catch (error) { // delete the folder to make sure build again. await removeDirAndFiles(this.getBotDir(botId)); - throw new Error(error.toString()); + throw error; } }; @@ -324,12 +334,11 @@ class LocalPublisher implements PublishPlugin { // start the bot process await this.startBot(botId, port, settings, project); } catch (error) { - console.error('Error in startbot: ', error); await this.stopBot(botId); this.setBotStatus(botId, { status: 500, result: { - message: error, + message: stringifyError(error), }, }); } From 2d261b4ef4bb8d028eebc0cbea561f54495b08b8 Mon Sep 17 00:00:00 2001 From: Wenyi Luo Date: Thu, 14 Jan 2021 11:20:30 +0800 Subject: [PATCH 2/3] stringify error by toString --- extensions/localPublish/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/localPublish/src/index.ts b/extensions/localPublish/src/index.ts index 569081f465..b8690156af 100644 --- a/extensions/localPublish/src/index.ts +++ b/extensions/localPublish/src/index.ts @@ -54,7 +54,7 @@ const isSkillHostUpdateRequired = (skillHostEndpoint?: string) => { const stringifyError = (error: any): string => { if (error instanceof Error) { - return `${error.name} - ${error.message}`; + return error.toString(); } else if (typeof error === 'object') { return JSON.stringify(error, Object.getOwnPropertyNames(error)); } else { From af395c797b883cf88f94dd52700dd943cd6c2ad9 Mon Sep 17 00:00:00 2001 From: Wenyi Luo Date: Mon, 18 Jan 2021 21:33:16 +0800 Subject: [PATCH 3/3] fix comment --- extensions/localPublish/src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extensions/localPublish/src/index.ts b/extensions/localPublish/src/index.ts index b8690156af..f00531b5b7 100644 --- a/extensions/localPublish/src/index.ts +++ b/extensions/localPublish/src/index.ts @@ -53,12 +53,10 @@ const isSkillHostUpdateRequired = (skillHostEndpoint?: string) => { }; const stringifyError = (error: any): string => { - if (error instanceof Error) { - return error.toString(); - } else if (typeof error === 'object') { + if (typeof error === 'object') { return JSON.stringify(error, Object.getOwnPropertyNames(error)); } else { - return error; + return error.toString(); } }