error-handlinglibrary-design

Error from format string

Box<dyn Error>::from(format!("...")) instead of a typed error.

Why this looks tempting

Quickest path: just stringify whatever, return as error.

Why wrong

The error becomes opaque text. Callers can't pattern-match, can't retry by category, can't attach structured logs. Every observability layer downstream loses signal.

Fix

Define an enum with variants for each failure mode. Implement From for upstream error types so ? propagates cleanly; preserve the chain via #[source].

Canonical alternative

error-handling/error-composition