-
Notifications
You must be signed in to change notification settings - Fork 7
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
Avoid dependencies on (external) error types #427
Comments
We're building a library, though, not an application, so
|
We need to support generic error types anyhow, since we provide an extension point that can return errors (that we do not know about yet). I don't think this is a library vs. application issue. Specific error messages are always nice, even in an application, but they require full knowledge of the possible errors upfront. |
It would be possible to mix the two approaches by having enum errors to distinguish "rough" types of potential issues, which internally wrap Boxed dyn errors as their causes. But it should not be so specific as to have different enums for every format that RIO supports. RIO should not be a dependency of nemo-physical. |
On that note, I am not sure it is ideal to have our "public api" depend on types of external crates, if we do consider our code "library code". |
Maybe it suffices to make the |
I am also not sure what potential users would want to deal with the huge amount of cases we currently provide. I believe to make the API actually useful, we'd need to split the error type based on what part of the API produces what error, and then return specific Error types instead of one catch-all. |
I also think that a catch-all enum is not the way to go. I would think that error-generalisation (more possible cases) should only occur along the error propagation path (as errors from several sources come together in one function that needs to pass them on). What we currently have is a design where error types are passed "sideways" and "downwards" so that they occur on paths that never deal with that type of error. I know of several possible designs for error handling in rust:
Pattern 4 is quite elegant, but only really works if the caller provides the most generic error (for the whole propagation path). This is easier when we have a single API function that has an "internal" Self::Error that one can extend, but hard if an extension point works as a call-back deep down in a propagation stack (as our file loading does). Dynamic errors are much easier in terms of coding, but lack the static information and might be difficult to match later on, which can possibly be alleviated by utility libraries like Are there any other options, or is this it? |
Ah, now I understand what this is really about. Still, I think that the idea that a caller must handle all variants of the error enum is fundamentally a misconception: a caller should handle exactly the errors they can actually recover from.
We already have |
Anyhow provides an idiomatic way for passing around errors without the need to keep every single one of them in a combined error enum, which should reduce inter-dependencies without limiting our ability to inspect errors later on.
The text was updated successfully, but these errors were encountered: