5 ms·
The way Go handled errors is why I made the decision to go with rust as my hobby/personal-open-source-projects language. It was just extremely tedious, despite
by munmaek 7y ago
The way Go handled errors is why I made the decision to go with rust as my hobby/personal-open-source-projects language. It was just extremely tedious, despite Go being nice overall.
I love how error handling is done in Rust. Yes, implementing the From<T> trait can get verbose, but wrapper libraries like Failure or Snafu exist now as well.
Being able to propagate errors down the line seamlessly with the ? operator and Result<T, E> type is nothing short of phenomenal. It looks like the next version of Rust will seamlessly allow using ? on None types as well.
- richardwhiuk 7y agoLook at the failure crate. For lots of errors, just treating them as a generic failure makes code a lot better.
- jedisct1 7y agoWhich is supposed to be replaced by https://github.com/withoutboats/fehler https://github.com/withoutboats/fehler
- munmaek 7y agoFehler is highly opinionated and I'm not sure it's worth it. IIRC the author posted on the /r/rust subreddit and was unable to take criticism at all. I don't like having to put decorators on functions and manually throw!()'ing. I would rather be explicit about returning Ok(T) or Err(E).
- munmaek 7y agoI did mention Failure/Snafu, but there are two problems with it: 1) The state of "how best to handle errors" keeps on changing. It was error_chain, then err-derive, then Failure, now Fehler or Snafu.. I would like to see this space calm down a bit. 2) Failure/Snafu require additional dependencies. For minimal libraries it's really not necessary to pull in so much when a a little boilerplate suffices. [0] [0]: https://git.sr.ht/~andrewzah/hangeul-rs/tree/master/src/errors.rs https://git.sr.ht/~andrewzah/hangeul-rs/tree/master/src/erro...
- karavelov 7y agoIt already handles Option returns through ? shorthand.
- munmaek 7y agoI was on 1.36.0 which complained about the None type not implementing From<T> I believe. If 1.38.0 handles it already then that's fantastic.