Skip to content

Conversation

@Frando
Copy link
Member

@Frando Frando commented Oct 20, 2025

Description

Changes the error handling across all crates in this repo from snafu/n0-snafu to n0-error. The latter is our new error library which features call-site location tracking and better ergonomics than snafu.

Repo: https://github.com/n0-computer/n0-error
Docs: https://docs.rs/n0-error/

Note: The initial version of this PR was written by an AI (OpenAI codex) which I instructed in numerous prompts to convert iroh from n0-snafu/snafu to n0-error. It has since been cleaned up and reviewed line-by-line.

Breaking Changes

Changed

  • All error structs and enum variants now have a field meta: n0_error::Meta. Fields backtrace and span_trace are removed.
  • All error structs and enums no longer implement snafu::ErrorCompat. They now implement n0_error::StackError. All our errors keep implementing std::error::Error. For downstream uses of these errors, not much changed.
  • If you previously used n0-snafu to work with iroh errors, we recommend you switch to n0-error. See the docs for how to work with n0-error.

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.
    • List all breaking changes in the above "Breaking Changes" section.
    • Open an issue or PR on any number0 repos that are affected by this breaking change. Give guidance on how the updates should be handled or do the actual updates themselves. The major ones are:

@Frando Frando mentioned this pull request Oct 20, 2025
11 tasks
@github-actions
Copy link

github-actions bot commented Oct 20, 2025

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

Last updated: 2025-11-03T18:49:21Z

@n0bot n0bot bot added this to iroh Oct 20, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Oct 20, 2025
@github-actions
Copy link

github-actions bot commented Oct 20, 2025

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 83e98fa

@Frando Frando changed the title refactor: convert from snafu to n0-error refactor!: convert from snafu to n0-error Oct 31, 2025
@dignifiedquire dignifiedquire added this to the v0.95 milestone Nov 1, 2025
disco::Message::from_bytes(&sealed_box).context(ParseSnafu)
.map_err(|source| e!(DiscoBoxError::Open { source }))?;
disco::Message::from_bytes(&sealed_box)
.map_err(|source| e!(DiscoBoxError::Parse { source }))
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between

e!(DiscoBoxError::Parse { source })

and

e!(DiscoBoxError::Parse, source)

Copy link
Member Author

Choose a reason for hiding this comment

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

None, they're identical. Both expand to DiscoBoxError::Parse { source, meta: Meta::default() }

## Description

`cargo fmt` can't handle code inside `tokio::select!` and the big match
statement had numerous formatting issues, so I moved it into a function.

## Breaking Changes

<!-- Optional, if there are any breaking changes document them,
including how to migrate older code. -->

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist
<!-- Remove any that are not relevant. -->
- [ ] Self-review.
- [ ] Documentation updates following the [style
guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text),
if relevant.
- [ ] Tests if relevant.
- [ ] All breaking changes documented.
- [ ] List all breaking changes in the above "Breaking Changes" section.
- [ ] Open an issue or PR on any number0 repos that are affected by this
breaking change. Give guidance on how the updates should be handled or
do the actual updates themselves. The major ones are:
    - [ ] [`quic-rpc`](https://github.com/n0-computer/quic-rpc)
    - [ ] [`iroh-gossip`](https://github.com/n0-computer/iroh-gossip)
    - [ ] [`iroh-blobs`](https://github.com/n0-computer/iroh-blobs)
    - [ ] [`dumbpipe`](https://github.com/n0-computer/dumbpipe)
    - [ ] [`sendme`](https://github.com/n0-computer/sendme)
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.

I only have small nits.

LGTM!

if response.status() != hyper::StatusCode::SWITCHING_PROTOCOLS {
UnexpectedUpgradeStatusSnafu {
code: response.status(),
n0_error::ensure!(
Copy link
Member

Choose a reason for hiding this comment

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

I think there's a place we missed importing the macro

Suggested change
n0_error::ensure!(
ensure!(

Copy link
Member Author

Choose a reason for hiding this comment

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

This function is #[cfg(not(wasm_browser))] and this is the only occurence of ensure in this module, so I left it like this instead of doing a conditional import of ensure at the module level.

#[cfg(not(feature = "test-utils"))]
{
snafu::whatever!(
n0_error::bail_any!(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: some more qualified uses

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in a conditioanl section, not sure what's better, keep it like this or conditional import at module level?

@Frando Frando enabled auto-merge November 3, 2025 18:50
@Frando Frando added this pull request to the merge queue Nov 3, 2025
Merged via the queue into main with commit 7b9c95b Nov 3, 2025
28 of 29 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants