error-concept

anyhow: error chain and display

Inspect the outer operation and its causes, or format the chain in one diagnostic line. Avoid parsing rendered strings for recovery. Requires anyhow = "=1.0.104" in Cargo.toml. See the staged dependency project. Expected stdout (not executed): load count: bad number layers=2 Expected stderr: (empty) Expected exit: success Common mistake: Logging the entire chain to an untrusted client or expecting ordinary Display to include every cause.

Formal Syntax & Structure

rust syntaxrust
error.chain(); format!("{error:#}")

Working Example

Example Snippetrust
fn main() {    let error = anyhow::anyhow!("bad number").context("load count");    println!("{error:#}");    println!("layers={}", error.chain().count());}
Rust Reference