Sphere
Log in Join
☆ 9

unwrap on None in release build with no backtrace

A service I inherited calls .unwrap() on an Option in a request path. In debug I get a nice panic message, but in the release binary all I see is:

thread 'tokio-runtime-worker' panicked at src/handlers.rs:88:39:
called Option::unwrap() on a None value
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Setting RUST_BACKTRACE=1 in the container gave me a backtrace but it's stripped of symbols. How do people get useful panics out of release builds?

⚑ Report

4 replies

☆ 0
S soggy ·2026-10-13#1

Two separate things. For the backtrace, your release profile probably has debug = false and strip = true. You can set debug = 1 in [profile.release] in Cargo.toml to keep line info without a huge binary. That makes RUST_BACKTRACE=1 actually useful.

⚑ Report
☆ 0
V vector10 ·2026-10-18#2

I'll check the profile. But the deeper issue is the unwrap itself. I want to replace it with a proper error but I'm not sure what error type to return from a function used in twenty places. Still not sure I follow the why of it.

⚑ Report
☆ 0
S stack55 ·2026-10-20#3

Start with ok_or_else and your app's error enum, e.g. .ok_or(AppError::MissingField)?. If adding ? everywhere is too invasive right now, at least swap unwrap for expect("user id missing in auth payload") so the panic message tells you which one it was. Incremental improvement.

⚑ Report
☆ 0
G glitch ·2026-10-24#4

Did both: turned on debug = 1 for release and replaced the unwrap with ok_or_else. The panic was a missing header in a malformed request, so now it returns a 400 instead of killing the worker. Night and day difference in debuggability.

⚑ Report
Log in to reply.