Skip to content

Commit

Permalink
Error info (#120)
Browse files Browse the repository at this point in the history
* fix error info

* update coverage

* add console error
  • Loading branch information
slavik-lvovsky authored Jan 23, 2020
1 parent a464187 commit 1278f5d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
6 changes: 3 additions & 3 deletions backend/.nycrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions backend/src/webSocketServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
}
}
Expand Down
23 changes: 21 additions & 2 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
return this.rpc.invoke("generatorDone", [true, message, targetPath]);
}

public setMessages(messages: any): Promise<void> {
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
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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", [{}]);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
},
Expand Down
3 changes: 0 additions & 3 deletions frontend/tests/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 1278f5d

Please sign in to comment.