Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Snafu for error handling #4053

Open
sandhose opened this issue Feb 18, 2025 · 0 comments
Open

Switch to Snafu for error handling #4053

sandhose opened this issue Feb 18, 2025 · 0 comments

Comments

@sandhose
Copy link
Member

We're not always doing a good job at reporting errors.

A few factors for this:

  • we rely on tracing::instrument(err) for logging when some function fails. This usually means that when an error bubbles up, it gets logged multiple times, with many times a lot of the tracing context in it
  • we don't consistently report them to sentry. In a lot of cases, we have a RouteError that calls sentry::capture_error, but we're missing that in multiple places
  • we use a mix of thiserror and anyhow, not very consistently. The fact that anyhow::Error doesn't implement std::error::Error is annoying
  • we often want to attach random string context to errors, which is annoying to do. In syn2mas we started using thiserror-ext exactly for that
  • we don't collect enough infos on errors. It would be nice to capture the code location where it was emitted, maybe the span context as well

Snafu looks nice to do all this:

  • it covers both the 'error derive macro' like thiserror and the 'whatever' error like anyhow
  • it automatically creates helper to add context on results, bundling the source error
  • when gathering context, it can automatically gather stuff like the backtrace, the code location or the span context
  • it's overall more opinionated, in a good way?
  • it adopts the new error 'provide' API. We could use that to try to define well-known error codes so that we can translate those to users?

We can try to gradually adopt it, as it works well with any error that implements std::error::Error anyway (which is the case for most of our code)

Related to #1488

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

No branches or pull requests

1 participant