From a2a1d5e7bb489b71c7e96283f8d8c87be387c6f4 Mon Sep 17 00:00:00 2001 From: tshino Date: Wed, 1 Dec 2021 22:47:10 +0900 Subject: [PATCH] Add check for validity of awaitOptions #11 --- generator/gen_keymap_wrapper.js | 10 ++++++++++ generator/gen_wrapper.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/generator/gen_keymap_wrapper.js b/generator/gen_keymap_wrapper.js index 00df8944..f26fca81 100644 --- a/generator/gen_keymap_wrapper.js +++ b/generator/gen_keymap_wrapper.js @@ -32,6 +32,15 @@ function makeWrapper(keybinding) { return wrapped; } +function checkAwaitOptions(awaitOptions) { + for (const awaitOption of awaitOptions.values()) { + if (!genWrapperUtil.isValidAwaitOption(awaitOption)) { + console.error('Error: Invalid awaitOption found:', awaitOption); + process.exit(1); + } + } +} + function resolveWildcardInAwaitOptions(awaitOptions, baseKeybindings) { const newAwaitOptions = new Map; for (const [ command, awaitOption ] of awaitOptions) { @@ -64,6 +73,7 @@ async function makeKeymapWrapper(configPath) { const rawAwaitOptions = new Map(config['awaitOptions'] || []); const awaitOptions = resolveWildcardInAwaitOptions(rawAwaitOptions, baseKeybindings); + checkAwaitOptions(awaitOptions); const wrappers = baseKeybindings.map( keybinding => { diff --git a/generator/gen_wrapper.js b/generator/gen_wrapper.js index cde7279a..fdf2cce3 100644 --- a/generator/gen_wrapper.js +++ b/generator/gen_wrapper.js @@ -31,12 +31,22 @@ function makeWrapper(keybinding) { return wrapped; } +function checkAwaitOptions(awaitOptions) { + for (const awaitOption of awaitOptions.values()) { + if (!genWrapperUtil.isValidAwaitOption(awaitOption)) { + console.error('Invalid awaitOption found:', awaitOption); + process.exit(1); + } + } +} + async function main() { const packageJson = await genWrapperUtil.readJSON(PackageJsonPath); const config = await genWrapperUtil.readJSON(ConfigPath); const exclusion = new Set(config['exclusion'] || []); const awaitOptions = new Map(config['awaitOptions'] || []); + checkAwaitOptions(awaitOptions); const baseKeybindings = await genWrapperUtil.loadBaseKeybindings(config['baseKeybindings'] || []);