Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gen_keymap_wrapper.js end with exit code 0 even when it fails #77

Merged
merged 3 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to the Keyboard Macro Bata extension will be documented in t
- Updated default keybindings based on VS Code 1.65.2. [#74](https://github.com/tshino/vscode-kb-macro/pull/74)
- Internal
- Added `record` option to the `kb-macro.wrap` command. [#76](https://github.com/tshino/vscode-kb-macro/pull/76)
- Fixed: gen_keymap_wrapper.js end with exit code 0 even when it fails [#77](https://github.com/tshino/vscode-kb-macro/pull/77)

### [0.11.3] - 2022-03-06
- Update
Expand Down
5 changes: 4 additions & 1 deletion generator/gen_keymap_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,7 @@ async function main() {
}
}

main();
main().catch(error => {
genWrapperUtil.error(error);
process.exit(1);
});
2 changes: 1 addition & 1 deletion generator/gen_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ async function main() {
}

main().catch(error => {
console.error(error);
genWrapperUtil.error(error);
process.exit(1);
});
7 changes: 3 additions & 4 deletions generator/gen_wrapper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const util = require('util');

function error(...msg) {
msg = [ '\u001b[31mError:' ].concat(msg).concat([ '\u001b[0m' ]);
console.log.apply(null, msg);
console.error.apply(null, msg);
}

function warn(...msg) {
msg = [ '\u001b[33mWarning:' ].concat(msg).concat([ '\u001b[0m' ]);
console.log.apply(null, msg);
console.warn.apply(null, msg);
}

async function readJSON(path, options = {}) {
Expand Down Expand Up @@ -196,8 +196,7 @@ function decomposeAwaitOption(awaitOption) {
const awaitList = parseAwaitOption(awaitOption);
const conditionals = awaitList.filter(a => a.condition);
if (1 < conditionals.length) {
error('Using multiple conditional await options is not supported');
throw 'error';
throw 'Using multiple conditional await options is not supported';
} else if (0 < conditionals.length) {
return [
{
Expand Down
12 changes: 12 additions & 0 deletions test/suite/gen_wrapper_util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,18 @@ describe('gen_wrapper_util', () => {
];
assert.deepStrictEqual(decomposeAwaitOption(input), expected);
});
it('should throw an error when there are multiple conditions', () => {
const input = '[cond1]await1 [cond2]await2';
assert.throws(
() => {
decomposeAwaitOption(input);
},
err => {
assert.strictEqual(err, 'Using multiple conditional await options is not supported');
return true;
}
);
});
});
describe('makeWrapperWhen', () => {
const makeWrapperWhen = genWrapperUtil.makeWrapperWhen;
Expand Down