Checks for ?
operators applied to values of type std::io::Result
.
Returning a std::io::Result
could mean relevant context (e.g., files or paths involved) is
lost. The problem is discussed under "Verbose IO errors" in Yoshua Wuyts' Error Handling
Survey.
No interprocedural analysis is done. So if context is added by the caller, it will go unnoticed.
fn foo() -> anyhow::Result<()> {
let _ = File::open("/nonexistent")?;
Ok(())
}
Use instead:
use anyhow::Context;
fn foo() -> anyhow::Result<()> {
let _ = File::open("/nonexistent").with_context(|| "could not open `/nonexistent`")?;
Ok(())
}