Repository navigation
fix(js): throw error when unsupported language is passed to CLI via -l / --lang - #1491
Merged
tushuhei merged 2 commits intoNov 4, 2026
Merged
Conversation
tushuhei
reviewed
Nov 3, 2026
tushuhei
left a comment
Member
There was a problem hiding this comment.
Thanks for your PR!
- Rather than adding an empty
if (model) {}branch and falling back toloadDefaultJapaneseParser()(which also lets-l ""silently fall back to Japanese and instantiates thejaparser twice), please set'ja'as the default value on.option('-l, --lang <str>', ..., 'ja')and resolveparserin a single lookup:
.option(
'-l, --lang <str>',
`language model to use. -m and --model will be prioritized if any.\navailable languages: ${[
...defaultParsers.keys(),
].join(', ')}`,
'ja'
) const {lang, model, delim, sep, html} = options as {
html: boolean;
delim: string;
sep: string;
model?: string;
lang: string;
};
const {args} = program;
const parser =
model !== undefined ? loadCustomParser(model) : defaultParsers.get(lang);
if (!parser) {
throw new Error(
`'${lang}' is not supported. Available languages: ${[
...defaultParsers.keys(),
].join(', ')}`
);
}(You can also remove the unused loadDefaultJapaneseParser import.)
- In
javascript/src/tests/cli_test.ts, please avoid carrying over thestabtypo (e.g., inlineexpect(() => cli(argv)).toThrowError(...)) and assert the full expected error message including[...loadDefaultParsers().keys()].join(', ').
tushuhei
requested changes
Nov 3, 2026
…mpty model branch, assert full error message in tests
Contributor
Author
|
Thank you for the review @tushuhei! I've addressed both points:
All 166 tests pass and biome check reports 0 errors. |
tushuhei
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When an unsupported language code is passed to the JavaScript CLI using
-lor--lang, throw an explicit error with the list of available languages instead of silently falling back to the Japanese parser.Problem
In
javascript/src/cli.ts, parser resolution was implemented as:If a caller supplied an unknown language (such as
budoux -l fr "Bonjour"), the conditionlang && defaultParsers.has(lang)evaluated tofalse, causing the CLI to silently default toloadDefaultJapaneseParser(). This resulted in unexpected Japanese-model segmentation instead of informing the user that the language was not recognized. In contrast, the Python CLI validates language options and produces a clear error.Solution
javascript/src/cli.ts: iflangis provided (andmodelis not overriding), verifydefaultParsers.has(lang). If not found, throw anErrorstating that the language is not supported and listing available supported languages.-land--langwith unsupported language inputs injavascript/src/tests/cli_test.ts.Testing
npx vitest runpassed across all 6 test suites (166 tests passed).node ./scripts/check-cli-version.jspassed.npx biome check src/cli.ts src/tests/cli_test.tspassed with 0 errors.Related Issue
Closes #1490