dtolnay / dtolnay/anyhow

Creating anyhow! from Arc<Error> miss error source

Open
#405 2 comments 3 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
6.7k
Forks
224
PR merge metrics
No merged PRs in 30d

Description

I'm trying to convert a `Arc` (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",
}'
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.