[BUG] Rust panic on unrecognized --dvblang value: Language::from_str().expect() in copy_to_rust()
Summary
Passing any unrecognized language code via --dvblang causes an unconditional
Rust panic that crashes the entire CCExtractor process with no user-facing error
message.
Location
src/rust/src/common.rs — copy_to_rust(), line ~427
Code
Language::from_str(&c_char_to_string(...)).expect("Invalid language")
Language::from_str() uses strum's EnumString derive. For any string not
in the Language enum (e.g. --dvblang xyz), it returns Err. The .expect()
call converts this into an unconditional panic, crashing the process instead of
printing a helpful CLI error.
Reproduction
ccextractor input.ts --dvblang xyz
# thread 'main' panicked at 'Invalid language', src/rust/src/common.rs:427
Expected Behaviour
CCExtractor should print a diagnostic like:
"Unknown language code 'xyz' — using default" and continue, or exit with a
clean error message.
Suggested Fix
Replace:
Language::from_str(&lang_str).expect("Invalid language")
With either:
// Option A — silent fallback
Language::from_str(&lang_str).unwrap_or_default()
// Option B — user-facing error (preferred)
Language::from_str(&lang_str).unwrap_or_else(|_| {
eprintln!("Warning: unknown language code '{}', using default", lang_str);
Language::default()
})
Environment
- Affects all platforms
- Reproducible with any unrecognized ISO 639 code passed to
--dvblang
Is anyone working in this?
Not a bug — the parser (parser.rs:703-711) already validates --dvblang with fatal!() before copy_to_rust() is ever called. The .expect() in copy_to_rust() is a defensive assertion against an internal inconsistency, not user input.