
Rust Error Called Option Unwrap on a None Value Explained
The panic called Option unwrap on a None value means a value you assumed was present was not. See how to find the line, and six patterns that replace the unwrap.
rustup, Clippy, rust-analyzer, debuggers and Git habits that shave minutes off every working day.

The panic called Option unwrap on a None value means a value you assumed was present was not. See how to find the line, and six patterns that replace the unwrap.

Seven usual causes of tests that pass and fail at random in Rust, with a check and a fix for each: shared state, ports, time, HashMap order, threads, files and the environment.

Binding a port that is taken fails with Address already in use, os error 98. Find the process holding it, handle TIME_WAIT and restarts, and fail with a useful message.

A Rust program that hangs is often a deadlock. Capture every thread's stack with gdb, parking_lot deadlock detection or tokio-console, and read who waits for what.

Find memory errors in unsafe Rust with AddressSanitizer, ThreadSanitizer and MemorySanitizer on nightly, and Miri for interpretation. Flags, build-std, output and limits.

Choose log levels by who reads them and when: what belongs at error, warn, info, debug and trace in a Rust service, what never to log, and how much is too much.

Tracing replaces log lines with spans and events: a span is a period of work, an event is a moment. Learn the macros, fields, instrument, subscribers and filters.

A Rust stack overflow aborts with thread main has overflowed its stack. Find the recursion or oversized local that caused it, then fix with a loop, a Vec, a Box or a bigger thread stack.

Debug Rust in VS Code with the CodeLLDB extension: install, a launch.json, breakpoints, conditional breakpoints, watch expressions, debugging tests and common problems.

Miri interprets your tests and reports undefined behavior in unsafe code: out of bounds access, use after free, bad aliasing and uninitialized reads. Here is how to run and read it.

A map of Rust debugging tools in the order to reach for them: compiler messages, dbg!, tests, backtraces, tracing, a debugger and sanitizers, with when each one wins.

Find where a Rust service's memory goes: read RSS and allocator stats, profile allocations with dhat or heaptrack, tell a leak from growth, and fix the usual causes.
We send one email when a new post is published. No spam.