Skip to content

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

@NexionisJake

Description

@NexionisJake

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.rscopy_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions