Skip to content

Commit

Permalink
error message (#108)
Browse files Browse the repository at this point in the history
* error message

* update version

* add test

* update logic

* update error message

* update error message

* version update
  • Loading branch information
slavik-lvovsky authored and tomer-epstein committed Jan 15, 2020
1 parent eb50c7b commit 5858d34
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.24",
"version": "0.0.25",
"engines": {
"vscode": "^1.38.0"
},
Expand Down
10 changes: 5 additions & 5 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yeoman-ui-frontend",
"displayName": "Yeoman UI Frontend",
"version": "0.2.3",
"version": "0.2.5",
"publisher": "SAP",
"license": "Apache 2.0",
"description": "Frontend for the yeoman UI framework",
Expand All @@ -15,14 +15,14 @@
"precommit": "lint-staged"
},
"dependencies": {
"@mdi/font": "^4.5.95",
"core-js": "2.6.6",
"jquery": "3.4.1",
"vue-loading-overlay": "^3.2.0",
"lodash": "^4.17.15",
"vue": "^2.6.10",
"vuetify": "^2.2.1",
"material-design-icons-iconfont": "^5.0.1",
"@mdi/font": "^4.5.95"
"vue": "^2.6.10",
"vue-loading-overlay": "^3.2.0",
"vuetify": "^2.2.1"
},
"devDependencies": {
"@sap-devx/webview-rpc": "^0.2.0",
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,15 @@ export default {
}
}
} catch (error) {
const message = `'${question.name}' question update of generator ${this.generatorName} has failed: ${_.get(error, "message", error)}`;
await this.rpc.invoke("logMessage", [message]);
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}`;
await this.rpc.invoke("logMessage", [errorMessage]);
this.rpc.invoke("toggleLog", [{}]);
}
},
Expand Down
29 changes: 27 additions & 2 deletions frontend/tests/App.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('App.vue', () => {
expect(wrapper.vm.prompts[0].questions[0].validationMessage ).toBeUndefined()
})

test('invoke for question that throws error', async () => {
test('invoke for question that throws error as string', async () => {
wrapper.vm.rpc = {
invoke: jest.fn().mockRejectedValueOnce("test error").mockResolvedValue()
}
Expand All @@ -157,13 +157,38 @@ describe('App.vue', () => {
}],
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', ["'validateQ' question update of generator has failed: test error"])
expect(invokeSpy).toHaveBeenCalledWith('logMessage', [`Failed to update 'validateQ' question in generator 'testGen'. Reason: test error`])
expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}])

invokeSpy.mockRestore();
})

test('invoke for question that throws error as error object', async () => {
wrapper.vm.rpc = {
invoke: jest.fn().mockRejectedValueOnce(new Error("test 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', [`Failed to update 'validateQ' question in generator 'testGen'. Reason: test error`])
expect(invokeSpy).toHaveBeenCalledWith('toggleLog', [{}])

invokeSpy.mockRestore();
})
})

Expand Down

0 comments on commit 5858d34

Please sign in to comment.