Skip to content

Commit 561c209

Browse files
committed
fix: pass a boxed cause through instead of restating it
The four errors that carry a cause boxed, because the trait they come from is implemented past a crate boundary, each rendered it with `#[snafu(display("{source}"))]`. That renders the cause as the wrapper's own message *and* still reports it from `Error::source()`, so every chain the cause appears in shows it twice: Error: unable to access network 'local', is it running? Caused by: 0: the local network for this project is not running 1: the local network for this project is not running `#[snafu(transparent)]` is what these want. Display still forwards to the cause, so the message is the same, but `source()` returns the cause's own source rather than the cause, and the wrapper stops being a link in the chain. Nothing below it is lost: a cause with sources of its own still contributes all of them. `LazyAgentError` was hand-written to do exactly this before it became a derive, down to a comment reading "as `snafu(transparent)` would", so for that one this is a restoration.
1 parent 4734c1f commit 561c209

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎crates/icp/src/agent.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a> LazyAgent<'a> {
5959
/// cause is carried whole and displayed as itself rather than being restated
6060
/// here.
6161
#[derive(Debug, Snafu)]
62-
#[snafu(display("{source}"))]
62+
#[snafu(transparent)]
6363
pub struct LazyAgentError {
6464
pub source: Box<dyn Error + Send + Sync + 'static>,
6565
}

‎crates/icp/src/canister/recipe/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct Fetched {
4343
/// project. This layer knows only that it can fail, so the cause is carried
4444
/// whole and displayed as itself.
4545
#[derive(Debug, Snafu)]
46-
#[snafu(display("{source}"))]
46+
#[snafu(transparent)]
4747
pub struct ResolveError {
4848
pub source: Box<dyn std::error::Error + Send + Sync + 'static>,
4949
}

‎crates/icp/src/canister/wasm.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::prelude::*;
1313
/// request and a write to a cache outside the project. This layer knows only
1414
/// that it can fail, so the cause is carried whole and displayed as itself.
1515
#[derive(Debug, Snafu)]
16-
#[snafu(display("{source}"))]
16+
#[snafu(transparent)]
1717
pub struct FetchError {
1818
pub source: Box<dyn std::error::Error + Send + Sync + 'static>,
1919
}

‎crates/icp/src/network/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl From<Mode> for Configuration {
330330
/// the user needs to be told, so the cause is carried whole and displayed as
331331
/// itself rather than being restated here.
332332
#[derive(Debug, Snafu)]
333-
#[snafu(display("{source}"))]
333+
#[snafu(transparent)]
334334
pub struct AccessError {
335335
pub source: Box<dyn std::error::Error + Send + Sync + 'static>,
336336
}

0 commit comments

Comments
 (0)