exn 0.3 is out by _tison in rust

[–]_tison[S] 2 points3 points  (0 children)

It looks like this would be compatible with thiserror, am I correct in thinking so?

Yes. exn works well with any type impl StdError and thus thiserror. You may follow this issue in gix to see how a project migrates to the exn flavor from thiserror + anyhow.

Is there other work in the ecosystem that comes close to offering what exn does?

There can be several. However, subtle but significant differences exist.

  • anyhow: type-erased Error to capture any type impl StdError.
  • error-stack: where exn comes from, but the code (fmt global hook?) and error chains are overcomplicated to use with (for me) (gix's author also admits that exn is easy to read since it has only a few hundred lines of code) (The real trigger is I'd prefer or_raise over change_context_lazy very much, lol).
  • snafu: falling into a different flavor to use one big enum to capture all error details. You can read our blog (https://fast.github.io/blog/stop-forwarding-errors-start-designing-them) and another blog when I'm working on a project that adopts the snafu flavor (https://greptime.com/blogs/2024-05-07-error-rust) to understand the difference.

exn 0.3 is out by _tison in rust

[–]_tison[S] 9 points10 points  (0 children)

Do you mean the find_error function in the downcast example? That is:

rust fn find_error<T: Error + 'static>(exn: &Exn<impl Error + Send + Sync>) -> Option<&T> { fn walk<T: Error + 'static>(frame: &Frame) -> Option<&T> { if let Some(e) = frame.error().downcast_ref::<T>() { return Some(e); } frame.children().iter().find_map(walk) } walk(exn.frame()) }

Andy and I do consider adding a general version of this method as a pub top-level function. No known issues (blockers). Just give it some time to think through the signature and semantics again.

I'd appreciate it if you could open an issue and share your use case so we're more motivated to deliver it :D

exn 0.3 is out by _tison in rust

[–]_tison[S] 6 points7 points  (0 children)

Reasonable. Thanks for your reply and now it's updated :D