vector: Improve error type handling
Many of Vector’s methods use a Result<_, String> return type. This is adequate for textual errors, but it makes it impossible for users to pattern match on the error type as well as dropping any cause information encapsulated by some error types. We should switch to proper error types (similar to std::io::Error) probably aided by the failure crate.
References:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 24 (24 by maintainers)
I’m not sure that it’s very high priority, but there is definitely still work that we could do to improve our error handling story. This initial pass at this used
snafu, but there have been quite a few uses ofanyhow/thiserrorthat have crept into the codebase over time, as well as a few areas where I think we’re still usingStringas our error type. There are also some newer crates likecolor-eyrethat have some nice integrations withtracingspans that could be useful for us. Overall, I think it would definitely be of some value to review what we’re doing and choose one consistent pattern.I would say we should take a quick inventory of components still using
Stringerrors and either add a checklist to this issue or break them out into individual issues so we can track overall progress (probably just a checklist here).I think the preferred path would be to introduce a
enum ConfigErroror equivalent and turn all those returns intoResult<…, Vec<ConfigError>>. At some layer, they may have to be boxed, but at the point they are emitted they can be enumerated and structured. Wrapping the error vector in a newtype as you describe would be a useful additional abstraction, but since they are all config errors, they can stay enumerated there.The whole configuration parsing stack still uses
Stringerror returns, mostly wrapped intoVec<String>. I have started working on this but pushed it aside to work on higher priority issues (TLS mostly). It was turning out to be less of a straightforward conversion that the sinks and sources were.A quick grep shows at least the following modules: