Skip to content

Conversation

Frando
Copy link
Member

@Frando Frando commented Jun 3, 2025

Description

This prints sources when using the alternate display ({:#}).

Example:

        let ep = Endpoint::builder()
            .bind_addr_v4("123.0.0.3:3".parse().unwrap())
            .bind()
            .await;
        if let Err(err) = ep {
            let err = n0_snafu::Error::from(err);
            println!("err display:");
            println!("{err}");
            println!("err alternate display:");
            println!("{err:#}");
        }

prints

err display:
Failed to create bind sockets
err alternate display:
Failed to create bind sockets: Cannot assign requested address (os error 99)

Before, the alternate display would be the same as the regular display (no sources).

Breaking Changes

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

Copy link

github-actions bot commented Jun 3, 2025

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/n0-snafu/pr/4/docs/n0_snafu/

Last updated: 2025-08-29T07:36:20Z

@matheus23
Copy link
Member

matheus23 commented Jun 6, 2025

Before we merge, we had a discussion about this on discord (and I agree):

I am not a fan of this
because this assumes a single source
so I think it should always be a list
my failure: because a: because b: because c
will now be the result for multiple sources
which is really not great
I think it should be

my failure:
 0: because a
 1: because b
 2: because c

or sth like that

(source)

@Frando Frando force-pushed the Frando/print-sources branch from a053414 to 1ca56f9 Compare July 4, 2025 21:54
Copy link
Member

@matheus23 matheus23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with this in the sense that we really need this 😅 (I keep hitting this)

But also: Given we use the same format as color-eyre for spantraces and backtraces, perhaps it'd make sense to use the same format for errors, too? https://lib.rs/crates/color-eyre

Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an improvement and we have a test to track the behaviour, we can always iterate on this

}
}

write!(f, "{self:#}")?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this prints the same stack now? especially it doesn't skip the root anymore, so you will end up printing that twice now I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not getting the root at all before, in the new test I added. Maybe needs more testing, also with all the different enum types of Error (tested only the whatever variant so far, I think).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: what is the difference between the Source and Message variants, couldn't they be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants