Skip to content

Fixed panicking unwrap() calls with clear error messages#124

Open
srishtiii28 wants to merge 1 commit intozmwangx:masterfrom
srishtiii28:fix/unwrap-panics
Open

Fixed panicking unwrap() calls with clear error messages#124
srishtiii28 wants to merge 1 commit intozmwangx:masterfrom
srishtiii28:fix/unwrap-panics

Conversation

@srishtiii28
Copy link

Problem

Closes #42.

Four places in build.rs called .unwrap() on values that can legitimately be None or Err in 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:

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', build.rs:210:46

Changes

  • Cross-compiler prefix (cross-compilation path): replaced file_stem().unwrap().to_str().unwrap() with an and_then() chain so a missing or non-UTF8 compiler path is silently skipped rather than panicking.
  • Include path (search_include): replaced .to_str().unwrap() with .to_string_lossy() to handle non-UTF8 Windows paths.
  • Lib search path (build feature path): replaced .to_str().unwrap() with .to_string_lossy() for the same reason.
  • pkg-config fallback (main fix): replaced bare .unwrap() on all three probe() calls with .unwrap_or_else() that emits a human-readable message telling the user exactly what to do:
Could not find FFmpeg via pkg-config. Please install the FFmpeg development
libraries (e.g. `apt install libavcodec-dev` on Debian/Ubuntu, `brew install
ffmpeg` on macOS, or vcpkg on Windows), or set the FFMPEG_DIR environment
variable to your FFmpeg install path, or enable the `build` feature to
compile FFmpeg from source.
pkg-config error: ...

Testing

Verified with cargo check — compiles with zero errors and zero warnings.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trouble building on target i686-pc-windows-msvc

1 participant