#405·anyhow

Creating anyhow! from Arc<Error> miss error source

Author: mickaelmagniezCreated Jan 17, 2025Updated Jul 1, 2026

I'm trying to convert a Arc<Error> (returned by moka crate) to an Error

So what i basically do is

rust
moka().map_err(|e| anyhow::anyhow!(e))?

But doing this, i lose information, before the map_err, printing with {:#} give me all the chained errors, but after the map_err, i get only the last one.

I've reproduced issue with the following code

rust
let error1 = anyhow::Error::msg("error1");
let error2 = anyhow::Error::from(error1).context("error2");
println!("error 2 '{:#}'", error2);
println!("error 2 src '{:?}'", error2.source());

is printing

error 2 'error2: error1'
error 2 src 'Some("error1")'

Recreating an error from error2 still works

rust
let error_from_error = anyhow::anyhow!(error2);

But if i try to do this this an Arc

rust
let arc_error = std::sync::Arc::new(error2);
let error_from_arc = anyhow::anyhow!(arc_error);
println!("src '{:?}'",  error_from_arc.source());
println!("error_from_arc '{:#}'", error_from_arc);

is printing

src 'None'
error_from_arc 'error2'

But

rust
println!("error_from_arc '{:#?}'", error_from_arc);

is printing

error_from_arc 'Error {
    context: "error2",
    source: "error1",
}'