Hey there, I'm fairly new to Rust and I'm trying to grok the current landscape of custom errors and handling.
I have a program that I'm slowly growing that talks to Neovim over RPC and a Clojure REPL over a socket. This means there's a bunch of connections and parsing, all of which can fail in interesting and colourful ways. I've just been returning String as my error type up until now since it's the only thing I actually understood.
I've been reading everything I can on failure
, error-chain
and "just use plain errors with custom macros" but I don't fully understand how I'm actually supposed to use any of them. How do they interact with the EDN parsing and RPC library errors for example. Like, am I supposed to wrap every error type in my own error type?
I was wondering if anyone had any tips on wrangling a bunch of different error types into something that wasn't a string. I only have one use case so far where I might want to behave differently depending on what sort of error was returned, the rest of the errors are just echoed to the user, so strings have been fine up until this point.
The one that sort of began to make sense was failure
, where the other errors I was seeing were cast into failure::Error
. And I think it would let me attach context strings somehow which could also be useful.
What's the current defacto for small-ish projects? Is there one? Is everything in a state of flux and nothing is the obvious answer? Because from my days of Googling, it's really feeling like the latter. I feel like I should just use normal Error without failure, but I honestly don't understand what that entails. Especially when I throw various library errors into the mix!
I hope someone out there has some tips on this, it'll be greatly appreciated. Hopefully this thread will be a good place for others in my position in the future too.
Here's my code at the time of writing this post, Result<T, String>
a plenty: https://github.com/Olical/conjure/tree/ba25c3891cbe7dc24fd9402d728ec037ad3f53e1