ccextractor icon indicating copy to clipboard operation
ccextractor copied to clipboard

[BUG] Rust panic on unrecognized --dvblang value: Language::from_str().expect() in copy_to_rust()

Open NexionisJake opened this issue 8 months ago • 2 comments

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

NexionisJake avatar Mar 26 '26 12:03 NexionisJake

Is anyone working in this?

ananyaaa66 avatar Mar 30 '26 11:03 ananyaaa66

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.

cfsmp3 avatar Apr 20 '26 06:04 cfsmp3