Fixed panicking unwrap() calls with clear error messages#124
Open
srishtiii28 wants to merge 1 commit intozmwangx:masterfrom
Open
Fixed panicking unwrap() calls with clear error messages#124srishtiii28 wants to merge 1 commit intozmwangx:masterfrom
srishtiii28 wants to merge 1 commit intozmwangx:masterfrom
Conversation
Four spots in build.rs called .unwrap() on values that can be None/Err in valid build environments, causing cryptic panics: - Cross-compiler path: file_stem().unwrap().to_str().unwrap() was replaced with and_then() so a missing or non-UTF8 path is silently skipped instead of panicking. - Include and lib search paths: .to_str().unwrap() was replaced with .to_string_lossy() to handle non-UTF8 Windows paths without panicking. - pkg-config fallback: bare .unwrap() on probe() was replaced with .unwrap_or_else() that emits a human-readable message telling the user exactly how to fix the problem (install FFmpeg, set FFMPEG_DIR, use vcpkg, or enable the build feature). Fixes zmwangx#42
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.
Problem
Closes #42.
Four places in
build.rscalled.unwrap()on values that can legitimately beNoneorErrin valid build environments, causing cryptic panics with no guidance for the user.The most impactful case is the pkg-config fallback path: on 32-bit Windows (
i686-pc-windows-msvc) and other platforms where pkg-config cannot locate FFmpeg, the bare.unwrap()causes a panic like:Changes
file_stem().unwrap().to_str().unwrap()with anand_then()chain so a missing or non-UTF8 compiler path is silently skipped rather than panicking.search_include): replaced.to_str().unwrap()with.to_string_lossy()to handle non-UTF8 Windows paths..to_str().unwrap()with.to_string_lossy()for the same reason..unwrap()on all threeprobe()calls with.unwrap_or_else()that emits a human-readable message telling the user exactly what to do:Testing
Verified with
cargo check— compiles with zero errors and zero warnings.