Skip to content

Commit

Permalink
Error handling (#157)
Browse files Browse the repository at this point in the history
* error_handling

* fix lint errors

* fix type
  • Loading branch information
slavik-lvovsky authored Feb 25, 2020
1 parent 0ce69ab commit 764cfba
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions 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.41",
"version": "0.0.42",
"engines": {
"vscode": "^1.39.2"
},
Expand Down Expand Up @@ -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"
},
Expand Down
10 changes: 5 additions & 5 deletions backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions backend/src/yeomanui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -174,8 +174,8 @@ export class YeomanUI {
return this.rpc.invoke("generatorInstall");
}

public doGeneratorDone(success: boolean, message: string, targetPath = ""): Promise<any> {
return this.rpc.invoke("generatorDone", [true, message, targetPath]);
public doGeneratorDone(suceeded: boolean, message: string, targetPath = ""): Promise<any> {
return this.rpc.invoke("generatorDone", [suceeded, message, targetPath]);
}

public setMessages(messages: any): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/yeomanui.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
2 changes: 1 addition & 1 deletion 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.3.6",
"version": "0.4.2",
"publisher": "SAP",
"license": "Apache 2.0",
"description": "Frontend for the yeoman UI framework",
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<v-col class="prompts-col" cols="12">
<Done
v-if="isDone"
:doneStatus="doneStatus"
:doneMessage="doneMessage"
:donePath="donePath"
/>
Expand Down Expand Up @@ -104,6 +105,7 @@ function initialState (){
reject: Object,
isDone: false,
doneMessage: Object,
doneStatus: false,
consoleClass: "",
logText: "",
showConsole: false,
Expand Down Expand Up @@ -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({
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/components/Done.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
style="height: 100%;"
>
<v-col align-self="center" class="done-column" cols="10">
<p class="done-message"><v-icon color="success" size="30">mdi-checkbox-marked-circle-outline</v-icon> {{doneMessage}}</p>
<p class="done-message"><v-icon :color="color" size="30">{{icon}}</v-icon> {{doneMessage}}</p>
</v-col>
</v-row>
</div>
Expand All @@ -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";
}
}
}
</script>

<style>
.done-message{
font-size: 1.25rem;
white-space:pre-wrap;
}
.done-column{
background-color: var(--vscode-editorWidget-background, #252526);
}
</style>
</style>
10 changes: 7 additions & 3 deletions frontend/tests/components/Done.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 764cfba

Please sign in to comment.