From 764cfba4ffd28f54af93458772efd5554135881d Mon Sep 17 00:00:00 2001 From: Stanislav Lvovsky Date: Tue, 25 Feb 2020 09:27:47 +0200 Subject: [PATCH] Error handling (#157) * error_handling * fix lint errors * fix type --- backend/package.json | 4 ++-- backend/src/extension.ts | 10 +++++----- backend/src/yeomanui.ts | 6 +++--- backend/tests/yeomanui.spec.ts | 2 +- frontend/jest.config.js | 8 ++++---- frontend/package.json | 2 +- frontend/src/App.vue | 5 ++++- frontend/src/components/Done.vue | 24 ++++++++++++------------ frontend/tests/components/Done.spec.js | 10 +++++++--- 9 files changed, 39 insertions(+), 32 deletions(-) diff --git a/backend/package.json b/backend/package.json index cb694207..f342b351 100644 --- a/backend/package.json +++ b/backend/package.json @@ -5,7 +5,7 @@ "license": "Apache 2.0", "description": "Provide rich user experience for Yeoman generators using VSCode extension or the browser", "repository": "https://github.com/SAP/yeoman-ui", - "version": "0.0.41", + "version": "0.0.42", "engines": { "vscode": "^1.39.2" }, @@ -62,7 +62,7 @@ "debug", "trace" ], - "default": "warn", + "default": "debug", "description": "The verbosity of logging according to the following order: trace > debug > info > warn > error > fatal > off.", "scope": "resource" }, diff --git a/backend/src/extension.ts b/backend/src/extension.ts index 92bf6442..455ed616 100644 --- a/backend/src/extension.ts +++ b/backend/src/extension.ts @@ -153,15 +153,15 @@ export class YeomanUIPanel { case 'showDoneMessage': const Close = 'Close'; const OpenWorkspace = 'Open Workspace'; - const commandName_Close = "workbench.action.closeActiveEditor"; - const commandName_OpenWorkspace = "vscode.openFolder"; - const commandParam_OpenWorkspace = _.get(message, "commandParams[0]"); + const commandNameClose = "workbench.action.closeActiveEditor"; + const commandNameOpenWorkspace = "vscode.openFolder"; + const commandParamOpenWorkspace = _.get(message, "commandParams[0]"); vscode.window.showInformationMessage('Where would you like to open the project?', Close , OpenWorkspace) .then(selection => { if (selection === Close) { - this.executeCommand(commandName_Close, undefined); + this.executeCommand(commandNameClose, undefined); } else if (selection === OpenWorkspace) { - this.executeCommand(commandName_OpenWorkspace, commandParam_OpenWorkspace); + this.executeCommand(commandNameOpenWorkspace, commandParamOpenWorkspace); } }); return; diff --git a/backend/src/yeomanui.ts b/backend/src/yeomanui.ts index 812afcc9..74dee31d 100644 --- a/backend/src/yeomanui.ts +++ b/backend/src/yeomanui.ts @@ -153,7 +153,7 @@ export class YeomanUI { let message: string; const destinationRoot = this.gen.destinationRoot(); if (err) { - message = `${generatorName} failed: ${err}.`; + message = `${generatorName} generator failed.\n\n${this.getErrorInfo(err)}`; this.logError(err, message); this.doGeneratorDone(false, message, destinationRoot); } else { @@ -174,8 +174,8 @@ export class YeomanUI { return this.rpc.invoke("generatorInstall"); } - public doGeneratorDone(success: boolean, message: string, targetPath = ""): Promise { - return this.rpc.invoke("generatorDone", [true, message, targetPath]); + public doGeneratorDone(suceeded: boolean, message: string, targetPath = ""): Promise { + return this.rpc.invoke("generatorDone", [suceeded, message, targetPath]); } public setMessages(messages: any): Promise { diff --git a/backend/tests/yeomanui.spec.ts b/backend/tests/yeomanui.spec.ts index c0b5b815..e517e700 100644 --- a/backend/tests/yeomanui.spec.ts +++ b/backend/tests/yeomanui.spec.ts @@ -85,7 +85,7 @@ describe('yeomanui unit test', () => { } } - const testLogger = {debug: () => {}, error: () => {}, fatal: () => {}, warn: () => {}, info: () => {}, trace: () => {}, getChildLogger: () => {return {} as IChildLogger;}}; + const testLogger = {debug: () => {}, error: () => {}, fatal: () => {}, warn: () => {}, info: () => {}, trace: () => {}, getChildLogger: () => ({} as IChildLogger)}; const rpc = new TestRpc(); const logger = new TestLog(); diff --git a/frontend/jest.config.js b/frontend/jest.config.js index 3403db4e..1e1f25bf 100644 --- a/frontend/jest.config.js +++ b/frontend/jest.config.js @@ -35,10 +35,10 @@ module.exports = { ], coverageThreshold: { "global": { - "branches": 92.6, - "functions": 97.1, - "lines": 95.9, - "statements": 95.9 + "branches": 92.9, + "functions": 97.2, + "lines": 96, + "statements": 96 } } } diff --git a/frontend/package.json b/frontend/package.json index f0825d32..5319cd5b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "yeoman-ui-frontend", "displayName": "Yeoman UI Frontend", - "version": "0.3.6", + "version": "0.4.2", "publisher": "SAP", "license": "Apache 2.0", "description": "Frontend for the yeoman UI framework", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 4210932b..cb5b29bd 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -27,6 +27,7 @@ @@ -104,6 +105,7 @@ function initialState (){ reject: Object, isDone: false, doneMessage: Object, + doneStatus: false, consoleClass: "", logText: "", showConsole: false, @@ -387,12 +389,13 @@ export default { }); } }, - generatorDone(success, message, targetPath) { + generatorDone(succeeded, message, targetPath) { if (this.currentPrompt.status === PENDING) { this.currentPrompt.name = "Summary"; } this.doneMessage = message; this.donePath = targetPath; + this.doneStatus = succeeded; this.isDone = true; if (this.isInVsCode()) { window.vscode.postMessage({ diff --git a/frontend/src/components/Done.vue b/frontend/src/components/Done.vue index dcae37bb..72553ad5 100644 --- a/frontend/src/components/Done.vue +++ b/frontend/src/components/Done.vue @@ -6,7 +6,7 @@ style="height: 100%;" > -

mdi-checkbox-marked-circle-outline {{doneMessage}}

+

{{icon}} {{doneMessage}}

@@ -15,24 +15,24 @@ export default { name: "Done", - props: ["doneMessage", "donePath"], - methods: { - // ISSUE: workbench.action.addRootFolder doesn't get params. - // openCurrentWorkspace(event) { - // close(event); - // event.currentTarget.dataset.commandName = "workbench.action.addRootFolder"; - // this.executeCommand(event); - // } - }, + props: ["doneStatus", "doneMessage", "donePath"], + computed: { + color() { + return this.doneStatus ? "green" : "red"; + }, + icon() { + return this.doneStatus ? "mdi-checkbox-marked-circle-outline" : "mdi-close-circle-outline"; + } + } } \ No newline at end of file + diff --git a/frontend/tests/components/Done.spec.js b/frontend/tests/components/Done.spec.js index 18f15302..6bf408a3 100644 --- a/frontend/tests/components/Done.spec.js +++ b/frontend/tests/components/Done.spec.js @@ -18,12 +18,16 @@ describe('Done.vue', () => { test('component props', () => { wrapper = initComponent(Done) - expect(_.keys(wrapper.props())).toHaveLength(2) + expect(_.keys(wrapper.props())).toHaveLength(3) }) - test('doneMessage set', () => { - wrapper = initComponent(Done, { doneMessage: testDoneMessage }) + test('doneMessage set, success', () => { + wrapper = initComponent(Done, { doneStatus: true, doneMessage: testDoneMessage }) expect(wrapper.find('p').text()).toBe('mdi-checkbox-marked-circle-outline testDoneMessage') }) + test('doneMessage set, failure', () => { + wrapper = initComponent(Done, { doneStatus: false, doneMessage: testDoneMessage }) + expect(wrapper.find('p').text()).toBe('mdi-close-circle-outline testDoneMessage') + }) })