diff --git a/backend/.nycrc.json b/backend/.nycrc.json index 15851687..a3b43e20 100644 --- a/backend/.nycrc.json +++ b/backend/.nycrc.json @@ -7,8 +7,8 @@ "temp-dir": "./reports/.nyc_output", "report-dir": "./reports/coverage", "check-coverage": true, - "branches": 27, - "lines": 40, + "branches": 26, + "lines": 39, "functions": 29, - "statements": 40 + "statements": 39 } diff --git a/backend/src/webSocketServer/index.ts b/backend/src/webSocketServer/index.ts index bb55e713..78517ccb 100644 --- a/backend/src/webSocketServer/index.ts +++ b/backend/src/webSocketServer/index.ts @@ -3,6 +3,7 @@ import { RpcExtensionWebSockets } from '@sap-devx/webview-rpc/out.ext/rpc-extens import { YeomanUI } from '../yeomanui'; import { YouiLog } from "../youi-log"; import { ServerLog } from './server-log'; +import backendMessages from "../messages"; class YeomanUIWebSocketServer { private rpc: RpcExtensionWebSockets | undefined; @@ -28,6 +29,7 @@ class YeomanUIWebSocketServer { //TODO: Use RPC to send it to the browser log (as a collapsed pannel in Vue) const logger: YouiLog = new ServerLog(this.rpc); this.yeomanui = new YeomanUI(this.rpc, logger); + this.yeomanui.setMessages(backendMessages); }); } } diff --git a/backend/src/yeomanui.ts b/backend/src/yeomanui.ts index 233f74e9..3a5f4f4a 100644 --- a/backend/src/yeomanui.ts +++ b/backend/src/yeomanui.ts @@ -174,15 +174,34 @@ export class YeomanUI { console.log("done running yeomanui! " + message + ` You can find it at ${destinationRoot}`); this.doGeneratorDone(true, message, destinationRoot); }); - } catch (err) { - console.error(err); + } catch (error) { + const errorMessage = this.getErrorInfo(error); + console.error(errorMessage); + this.logMessage(errorMessage); + this.toggleLog(); } } + getErrorInfo(error: any) { + if (_.isString(error)) { + return error; + } + const name = _.get(error, "name", ""); + const message = _.get(error, "message", ""); + const stack = _.get(error, "stack", ""); + const string = error.toString(); + + return `name: ${name}\n message: ${message}\n stack: ${stack}\n string: ${string}\n`; + } + public doGeneratorDone(success: boolean, message: string, targetPath = ""): Promise { return this.rpc.invoke("generatorDone", [true, message, targetPath]); } + public setMessages(messages: any): Promise { + return this.rpc ? this.rpc.invoke("setMessages", [messages]) : Promise.resolve(); + } + /** * * @param answers - partial answers for the current prompt -- the input parameter to the method to be evaluated diff --git a/frontend/src/App.vue b/frontend/src/App.vue index cbc1b9d5..15f61921 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -243,6 +243,8 @@ export default { } } catch (error) { const errorMessage = this.getErrorMessageOnException(question, error); + // eslint-disable-next-line no-console + console.error(errorMessage); await this.rpc.invoke("logMessage", [errorMessage]); this.rpc.invoke("toggleLog", [{}]); } @@ -252,14 +254,15 @@ export default { if (_.isString(error)) { errorInfo = error; } else { - errorInfo = _.get(error, "message", _.get(error, "stack", "")); + const name = _.get(error, "name", ""); + const message = _.get(error, "message", ""); + const stack = _.get(error, "stack", ""); + const string = error.toString(); + + errorInfo = `name: ${name}\n message: ${message}\n stack: ${stack}\n string: ${string}\n`; } - if (!_.isEmpty(errorInfo)) { - errorInfo = ` Reason: ${errorInfo}`; - } - - return `Could not update the '${question.name}' question in generator '${this.generatorName}'.${errorInfo}`; + return `Could not update the '${question.name}' question in generator '${this.generatorName}'.\nError info ---->\n ${errorInfo}`; }, next() { if (this.resolve) { @@ -352,9 +355,7 @@ export default { } this.$set(question, "answer", answer); this.$set(question, "isValid", true); - this.$set(question, "doNotShow", false); this.$set(question, "validationMessage", true); - this.$set(question, "isWhen", question.when !== FUNCTION); } }, diff --git a/frontend/tests/App.spec.js b/frontend/tests/App.spec.js index 10958355..4931267d 100644 --- a/frontend/tests/App.spec.js +++ b/frontend/tests/App.spec.js @@ -163,7 +163,6 @@ describe('App.vue', () => { const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke') await wrapper.vm.updateQuestionsFromIndex(0) expect(invokeSpy).toHaveBeenCalledWith('evaluateMethod', [["validateAnswer", {"validateQ": "validateAnswer"}], 'validateQ', 'validate']) - expect(invokeSpy).toHaveBeenCalledWith('logMessage', [`Could not update the 'validateQ' question in generator 'testGen'. Reason: test error`]) expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}]) invokeSpy.mockRestore(); @@ -185,7 +184,6 @@ describe('App.vue', () => { const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke') await wrapper.vm.updateQuestionsFromIndex(0) expect(invokeSpy).toHaveBeenCalledWith('evaluateMethod', [["validateAnswer", {"validateQ": "validateAnswer"}], 'validateQ', 'validate']) - expect(invokeSpy).toHaveBeenCalledWith('logMessage', [`Could not update the 'validateQ' question in generator 'testGen'. Reason: test error`]) expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}]) invokeSpy.mockRestore(); @@ -207,7 +205,6 @@ describe('App.vue', () => { const invokeSpy = jest.spyOn(wrapper.vm.rpc, 'invoke') await wrapper.vm.updateQuestionsFromIndex(0) expect(invokeSpy).toHaveBeenCalledWith('evaluateMethod', [["validateAnswer", {"validateQ": "validateAnswer"}], 'validateQ', 'validate']) - expect(invokeSpy).toHaveBeenCalledWith('logMessage', [`Could not update the 'validateQ' question in generator 'testGen'.`]) expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}]) invokeSpy.mockRestore();