budoux icon indicating copy to clipboard operation
budoux copied to clipboard

fix(js): throw error when unsupported language is passed to CLI via -l / --lang

Open codeXsidd opened this issue 1 month ago • 0 comments

Problem

When an unsupported language code is passed to the JavaScript CLI using -l or --lang, the CLI silently ignores the invalid argument and falls back to using the default Japanese parser without warning or error.

In contrast, the Python CLI validates the language code and raises an informative error listing the supported languages:

budoux: error: argument -l/--lang: 'xyz' does not exist in builtin models. (supported languages: ['ja', 'ja_word', 'th', 'zh-hans', 'zh-hant'])

Current Behavior

In javascript/src/cli.ts (lines 73-77):

  const parser = model
    ? loadCustomParser(model)
    : lang && defaultParsers.has(lang)
      ? defaultParsers.get(lang)!
      : loadDefaultJapaneseParser();

If lang is provided but does not match any entry in defaultParsers (e.g. budoux -l fr "Bonjour"), it silently falls back to loadDefaultJapaneseParser(). This produces unexpected segmentation using the Japanese model rather than notifying the user of an invalid option.

Expected Behavior

When -l or --lang is provided with a language that does not exist in defaultParsers, the CLI should throw an Error indicating that the language is not supported and listing the available supported languages.

Reproduction

budoux -l unknown "Some text"
# Currently succeeds and segments using Japanese model
# Should throw an error: "'unknown' is not supported. Available languages: ja, zh-hans, zh-hant, th"

Technical Context

  • Location: javascript/src/cli.ts
  • defaultParsers map contains all supported languages: [...defaultParsers.keys()].join(', ').
  • When lang is provided and !defaultParsers.has(lang), throw an Error indicating that the language is not supported.

codeXsidd avatar Nov 02 '26 17:11 codeXsidd