[FIX]: Replace Language::from_str().expect() with graceful fallback in copy_to_rust()#2238
Open
NexionisJake wants to merge 1 commit intoCCExtractor:masterfrom
Open
Conversation
Language::from_str().expect("Invalid language") panicked unconditionally
when the user passed any string not in the Language enum (e.g. --dvblang xyz),
producing a raw Rust panic instead of a useful error message.
Replace .expect() with .unwrap_or_else() that prints a human-readable warning:
"Warning: unrecognized language code 'xyz', defaulting to 'und'"
and falls back to Language::default(), allowing CCExtractor to continue
processing rather than crashing.
Fixes CCExtractor#2231
Collaborator
CCExtractor CI platform finished running the test files on linux. Below is a summary of the test results, when compared to test for commit d56a6be...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
Collaborator
CCExtractor CI platform finished running the test files on windows. Below is a summary of the test results, when compared to test for commit d56a6be...:
Your PR breaks these cases:
NOTE: The following tests have been failing on the master branch as well as the PR:
Congratulations: Merging this PR would fix the following tests:
It seems that not all tests were passed completely. This is an indication that the output of some files is not as expected (but might be according to you). Check the result page for more info. |
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.
In raising this pull request, I confirm the following :
Reason for this PR:
exists.
Sanity check:
guide.
the changelog.
Repro instructions:
ccextractor input.ts --dvblang xyz With any unrecognized language code, CCExtractor panics immediately: thread 'main' panicked at 'Invalid language', src/rust/src/common.rs:427 No subtitle extraction occurs and no useful error is shown to the user. --- Root cause Language::from_str(&lang_str).expect("Invalid language") in copy_to_rust() (src/rust/src/common.rs) uses strum's EnumString derive. For any string not present in the Language enum, from_str() returns Err and .expect() panics unconditionally — crashing the process instead of emitting an error message. Fix Replaced .expect("Invalid language") with .unwrap_or_else(|_| { … }) that prints a descriptive warning to stderr and falls back to Language::default() (Language::Und), allowing CCExtractor to continue processing. Before: Language::from_str(&c_char_to_string((*ccx_s_options).dvblang)) .expect("Invalid language") // --dvblang xyz → thread 'main' panicked at 'Invalid language' After: let lang_str = c_char_to_string((*ccx_s_options).dvblang); Language::from_str(&lang_str).unwrap_or_else(|_| { eprintln!("Warning: unrecognized language code '{lang_str}', defaulting to 'und'"); Language::default() }) // --dvblang xyz → Warning: unrecognized language code 'xyz', defaulting to 'und' Only src/rust/src/common.rs is changed. cargo build and cargo clippy both pass with zero new warnings. Fixes #2231