fix(speech): validate --words JSON before auth

Invalid vocabulary JSON was parsed in run(), so CI without an API key failed with AUTH(3) instead of USAGE(2).
This commit is contained in:
clh02467605
2026-09-10 14:28:16 +08:00
parent 7803d91e3f
commit 16e30686f0
@@ -1,6 +1,7 @@
import {
readTextFromPathOrStdin,
parseVocabularyEntries,
UsageError,
type FlagsDef,
type ParsedFlags,
type VocabularyEntry,
@@ -61,6 +62,17 @@ export function validateVocabularySource(flags: VocabularySourceFlags): string |
if (flags.words && flags.wordsFile) {
return "Use either --words or --words-file, not both.";
}
if (!flags.words) {
return undefined;
}
try {
parseVocabularyEntries(flags.words, flags.lang);
} catch (error) {
if (error instanceof UsageError) {
return error.message;
}
throw error;
}
return undefined;
}