Better error handling #10

Closed
opened 2026-06-26 15:59:26 +00:00 by decentral1se · 4 comments
Owner

It would be nice if we could avoid the thing we're doing as it's a bit clunky:

if err != nil {
  irohErr := &iroh.IrohError{}
  if ok := errors.As(err, irohErr); ok {
    panic(irohErr.Message())
  } else {
    panic(err)
  }
}

And instead just expose the error types directly:

https://github.com/n0-computer/iroh-ffi/blob/87509053e1dbe1e561c4abb0cd08481441c0edcb/src/error.rs#L39-L57

Then people can errors.Is(...) (or whatever) directly to check without the casting. I don't actually see this exposed in the API via the docs: https://godocs.io/git.coopcloud.tech/decentral1se/iroh-go so there might need to be some automagic conversion done 🤔

It would be nice if we could avoid the thing we're doing as it's a bit clunky: ```go if err != nil { irohErr := &iroh.IrohError{} if ok := errors.As(err, irohErr); ok { panic(irohErr.Message()) } else { panic(err) } } ``` And instead just expose the error types directly: > https://github.com/n0-computer/iroh-ffi/blob/87509053e1dbe1e561c4abb0cd08481441c0edcb/src/error.rs#L39-L57 Then people can `errors.Is(...)` (or whatever) directly to check without the casting. I don't actually see this exposed in the API via the docs: https://godocs.io/git.coopcloud.tech/decentral1se/iroh-go so there might need to be some automagic conversion done 🤔
Collaborator

yeah i was thinking of this too! big fan of being able to use errors.Is if possible

yeah i was thinking of this too! big fan of being able to use errors.Is if possible
Author
Owner

I've raised it upstream: https://github.com/n0-computer/iroh-ffi/issues/263

We need everything that should be IrohError to be typed as IrohError and not error. That is the first step. Then we can implement errors.Is for IrohError to match against the whole family of errors that come from the iroh side. We can build the errors out as concrete types as we come across them.

If upstream can't help with a change, we can try to hack the bindings again 😬 Waiting for now...

I've raised it upstream: https://github.com/n0-computer/iroh-ffi/issues/263 We need everything that should be `IrohError` to be typed as `IrohError` and not `error`. That is the first step. Then we can implement `errors.Is` for `IrohError` to match against the whole family of errors that come from the `iroh` side. We can build the errors out as concrete types as we come across them. If upstream can't help with a change, we can try to hack the bindings again 😬 Waiting for now...
decentral1se self-assigned this 2026-06-29 17:47:21 +00:00
decentral1se removed their assignment 2026-06-30 09:48:05 +00:00
Author
Owner

This can now be integrated 🪇 I'm just not sure if there is a release coming soon or not. For now, we can build off of a commit and get a draft out on our side also. Super cool stuff!

https://github.com/n0-computer/iroh-ffi/pull/267

edit: release has dropped: https://github.com/n0-computer/iroh-ffi/releases/tag/v1.1.0

This can now be integrated 🪇 ~~I'm just not sure if there is a release coming soon or not. For now, we can build off of a commit and get a draft out on our side also. Super cool stuff!~~ > https://github.com/n0-computer/iroh-ffi/pull/267 **edit**: release has dropped: https://github.com/n0-computer/iroh-ffi/releases/tag/v1.1.0
Author
Owner

Running out of time just now but I've merged the latest v1.1.0 release in and updated the examples to build from the latest HEAD and everything is still working! What is now is to write the wrapper for more ergonomic errors following the tips in https://github.com/n0-computer/iroh-ffi/issues/263#issuecomment-4925687805. Unless someone gets to it first, I'll take a crack shortly.

Running out of time just now but I've [merged the latest `v1.1.0` release](https://git.coopcloud.tech/decentral1se/iroh-go/commit/68ad06fe2a2507afd217e88d18a967204d5b8935) in and updated the examples to build from the latest HEAD and everything is still working! What is now is to write the wrapper for more ergonomic errors following the tips in https://github.com/n0-computer/iroh-ffi/issues/263#issuecomment-4925687805. Unless someone gets to it first, I'll take a crack shortly.
Sign in to join this conversation.
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: decentral1se/iroh-go#10