NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io, #67 most downloaded on crates.io
Flexible concrete Error type built on std::error::Error
Latest stable
1.0.104
Last release 4 months ago
18 Jul 2026
Release timing varies
gaps range from 2 weeks to 5 months
Most releases are documented
notes for 51 of the last 60 stable releases
3 versions withdrawn
withdrawn after publishing
7 years old
106 releases · first in 2019
Drag across the ruler to compare, or tap a release to open it.
Mark error constructors cold to help LLVM optimize code paths not leading to error (#166, thanks @stepancheg)
Take -Zallow-features restrictions from Cargo configuration file into account on sufficiently new versions of nightly Cargo (#157, thanks @jonhoo)
Enable Android's automated tooling to pull in test coverage improvements
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Disallow incompatible old versions of backtrace crate (#155, thanks @jfirebaugh)
Reduce memory footprint of errors on Rust versions 1.51+
Add an opt-in implementation of `Error::backtrace` on stable compilers based on the backtrace crate
Add an opt-in implementation of Error::backtrace on stable compilers based on the backtrace crate (#143)
[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
Support using anyhow::Error in code executed by Miri (#134, thanks @thomcc)
Improve compiler diagnostic on calling macro with a temporary value
Make anyhow::Error ABI compatible with void* for round tripping through a C FFI
void* for round tripping through a C FFI (#132)Support 1-argument use of ensure!
Support 1-argument use of ensure! (#126)
ensure!(depth <= MAX_DEPTH);
// error msg on a false condition would be "Condition failed: `depth <= MAX_DEPTH`"
Fix semicolon use in bail! macro in preparation for https://github.com/rust-lang/rust/pull/78685
bail! macro in preparation for https://github.com/rust-lang/rust/pull/78685 (#120)Clarify documentation of anyhow!, bail!, ensure! macros
anyhow!, bail!, ensure! macros (#114)- Add impl From for Box
impl From<anyhow::Error> for Box<dyn Error + Send + 'static> (#103)Restore "Stack backtrace" header label above the backtrace in {:?} representation
{:?} representation (#92)Hide an error message that appears when building with cargo rustc -vv (#91, thanks @eoger)
cargo rustc -vv (#91, thanks @eoger)Nothing published for this version
Documentation improvements (#73, #78)
Improve documentation of backtrace environment variable combinations
Improve documentation of backtrace environment variable combinations (#69)
- If you want panics and errors to both have backtraces, set
RUST_BACKTRACE=1;- If you want only errors to have backtraces, set
RUST_LIB_BACKTRACE=1;- If you want only panics to have backtraces, set
RUST_BACKTRACE=1andRUST_LIB_BACKTRACE=0.
Fix indentation when printing causes that have a multiline error message (#54, thanks @yaahc)
In no_std mode, the same API is almost all available and works the same way. To depend on Anyhow in no_std mode, disable our default enabled "std" fea
Add no-std support (#53)
In no_std mode, the same API is almost all available and works the same way. To depend on Anyhow in no_std mode, disable our default enabled "std" feature in Cargo.toml. A global allocator is required.
[dependencies]
anyhow = { version = "1.0", default-features = false }
Since the ?-based error conversions would normally rely on the std::error::Error trait which is only available through std, no_std mode will require an explicit .map_err(Error::msg) when working with a non-Anyhow error type inside a function that returns Anyhow's error type.
Preserve cause chain when converting from Box\ to anyhow::Error
Add impl AsRef and impl AsRef for anyhow::Error
impl AsRef<dyn std::error::Error> and impl AsRef<dyn std::error::Error + Send + Sync> for anyhow::ErrorChain::new constructorPreserve cause chain when bail! or ensure! is invoked with anyhow::Error as the error argument
bail! or ensure! is invoked with anyhow::Error as the error argument (#46)Provide DoubleEndedIterator and ExactSizeIterator implementations for anyhow::Chain to assist in custom rendering of cause chains
Provide DoubleEndedIterator and ExactSizeIterator implementations for anyhow::Chain to assist in custom rendering of cause chains (#45)
let chain = err.chain();
if chain.len() > 1 {
eprint!("[[root cause]] ");
}
for err in chain.rev() {
eprintln!("{}", err);
}
Introduce some {:#} and {:#?} alt formatting representations
Introduce some {:#} and {:#?} alt formatting representations (#42)
When you print an error object using "{}" or to_string(), only the outermost underlying error or context is printed, not any of the lower level causes. This is exactly as if you had called the Display impl of the error from which you constructed your anyhow::Error.
Failed to read instrs from ./path/to/instrs.json
To print causes as well using anyhow's default formatting of causes, use the alternate selector "{:#}".
Failed to read instrs from ./path/to/instrs.json: No such file or directory (os error 2)
The Debug format "{:?}" includes your backtrace if one was captured. Note that this is the representation you get by default if you return an error from fn main instead of printing it explicitly yourself.
Error: Failed to read instrs from ./path/to/instrs.json
Caused by:
No such file or directory (os error 2)
Stack backtrace:
0: <E as anyhow::context::ext::StdError>::ext_context
at /git/anyhow/src/backtrace.rs:26
1: core::result::Result<T,E>::map_err
at /git/rustc/src/libcore/result.rs:596
2: anyhow::context::<impl anyhow::Context<T,E> for core::result::Result<T,E>>::with_context
at /git/anyhow/src/context.rs:58
3: testing::main
at src/main.rs:5
4: std::rt::lang_start
at /git/rustc/src/libstd/rt.rs:61
5: main
6: __libc_start_main
7: _start
To see a conventional struct-style Debug representation, use "{:#?}".
Error {
context: "Failed to read instrs from ./path/to/instrs.json",
source: Os {
code: 2,
kind: NotFound,
message: "No such file or directory",
},
}
If none of the built-in representations are appropriate and you would prefer to render the error and its cause chain yourself, it can be done something like this:
use anyhow::{Context, Result};
fn main() {
if let Err(err) = try_main() {
eprintln!("ERROR: {}", err);
err.chain().skip(1).for_each(|cause| eprintln!("because: {}", cause));
std::process::exit(1);
}
}
fn try_main() -> Result<()> {
...
}
Export anyhow! also under the alias format_err!
anyhow! also under the alias format_err! (#37)Support downcasting errors with context to the context's type C *or* to the underlying error type E
Support downcasting errors with context to the context's type C or to the underlying error type E (#34)
That is, in codebases that rely on downcasting, Anyhow's context now supports both of the following use cases:
Attaching context whose type is insignificant onto errors whose type is used in downcasts.
In other error libraries whose context is not designed this way, it can be risky to introduce context to existing code because new context might break existing working downcasts. In Anyhow, any downcast that worked before adding context will continue to work after you add a context, so you should freely add human-readable context to errors wherever it would be helpful.
use anyhow::{Context, Result};
fn do_it() -> Result<()> {
helper().context("failed to complete the work")?;
...
}
fn main() {
let err = do_it().unwrap_err();
if let Some(e) = err.downcast_ref::<SuspiciousError>() {
// If helper() returned SuspiciousError, this downcast will
// correctly succeed even with the context in between.
}
}
Attaching context whose type is used in downcasts onto errors whose type is insignificant.
Some codebases prefer to use machine-readable context to categorize lower level errors in a way that will be actionable to higher levels of the application.
use anyhow::{Context, Result};
fn do_it() -> Result<()> {
helper().context(HelperFailed)?;
...
}
fn main() {
let err = do_it().unwrap_err();
if let Some(e) = err.downcast_ref::<HelperFailed>() {
// If helper failed, this downcast will succeed because
// HelperFailed is the context that has been attached to
// that error.
}
}
Work around poor paths in compiler diagnostic when missing Context import
Context import (#30)- Add impl From for Box
impl From<anyhow::Error> for Box<dyn std::error::Error + 'static> (#25)Nothing published for this version
Replace compiler version detection with probing the Backtrace api to be more resilient to nightly development of backtrace feature
Support building with dev toolchains older than 1.40.0-nightly
Improve return type inference when calling .context(...) on a Result
.context(...) on a Result (#18)Fix UB when accessing errors with large alignment (#16, thanks @johnschug)
Documentation improvements: show example of thiserror's derive(Error)
derive(Error)Seal the Context trait as it is not intended to be implemented outside of anyhow
Context trait as it is not intended to be implemented outside of anyhowPreserve the source and backtrace of error expressions passed to anyhow!($expr)
anyhow!($expr)Nothing published for this version
Preserve source and backtrace when converting from anyhow::Error to Box\
- Add impl From for Box
impl From<anyhow::Error> for Box<dyn std::error::Error + Send + Sync + 'static> (#10)Make the Result type alias more flexible (#11, thanks @amesgen)
Allow .context(...) and .with_context(|| ...) on Option\
.context(...) and .with_context(|| ...) on Option<T>Eliminate reliance on unstable trait object layout (#5, thanks @johnschug)
Add `ensure!` macro (#4, thanks @repi)
ensure! macro (#4, thanks @repi)bail! (#2, thanks @repi)Nothing published for this version
Nothing published for this version
One column per quarter.