Skip to content

Commit

Permalink
update exception message (#110)
Browse files Browse the repository at this point in the history
* update exception message

* add test
  • Loading branch information
slavik-lvovsky authored and tomer-epstein committed Jan 16, 2020
1 parent f8a23bf commit 198c08a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
],
coverageThreshold: {
"global": {
"branches": 85,
"branches": 86,
"functions": 98,
"lines": 95,
"statements": 95
Expand Down
23 changes: 15 additions & 8 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,25 @@ export default {
}
}
} catch (error) {
let errorInfo = "No failure info";
if (_.isString(error)) {
errorInfo = error;
} else {
errorInfo = _.get(error, "message", _.get(error, "stack", errorInfo));
}
const errorMessage = `Failed to update '${question.name}' question in generator '${this.generatorName}'. Reason: ${errorInfo}`;
const errorMessage = this.getErrorMessageOnException(question, error);
await this.rpc.invoke("logMessage", [errorMessage]);
this.rpc.invoke("toggleLog", [{}]);
}
},
getErrorMessageOnException(question, error) {
let errorInfo;
if (_.isString(error)) {
errorInfo = error;
} else {
errorInfo = _.get(error, "message", _.get(error, "stack", ""));
}
if (!_.isEmpty(errorInfo)) {
errorInfo = ` Reason: ${errorInfo}`;
}
return `Could not update the '${question.name}' question in generator '${this.generatorName}'.${errorInfo}`;
},
next() {
if (this.resolve) {
try {
Expand Down
26 changes: 24 additions & 2 deletions frontend/tests/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ 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', [`Failed to update 'validateQ' question in generator 'testGen'. Reason: test error`])
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 +185,29 @@ 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', [`Failed to update 'validateQ' question in generator 'testGen'. Reason: test error`])
expect(invokeSpy).toHaveBeenCalledWith('logMessage', [`Could not update the 'validateQ' question in generator 'testGen'. Reason: test error`])
expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}])

invokeSpy.mockRestore();
})

test('invoke for question that throws error as error object without message', async () => {
wrapper.vm.rpc = {
invoke: jest.fn().mockRejectedValueOnce(new Error()).mockResolvedValue()
}
wrapper.vm.prompts = [{
questions: [{
name: 'validateQ', validate: '__Function', answer: 'validateAnswer', isWhen: true, doNotShow: false
}],
answers: {}
}]
wrapper.vm.generatorName = "testGen";
wrapper.vm.promptIndex = 0

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 198c08a

Please sign in to comment.