4 ms·
The progress on the error messages truly is worth highlighting, and kudos to the team for all the hard work there. It's one of the hardest things to get right i
by ojnabieoot 6y ago
The progress on the error messages truly is worth highlighting, and kudos to the team for all the hard work there. It's one of the hardest things to get right in a programming language, particularly if that language has a fussy compiler.
- empath75 6y agoI’ve been using the anyhow crate and it’s made error handling almost painless.
- GolDDranks 6y agoYou are talking about different things, the grandparent was talking about the compiler error messages. Just a note, I agree with both of you :)
- jrimbault 6y agoJust to point out for other readers, nowadays to make a custom error type you just need : - an enum (or struct) - its Display implementation - its Error implementation, now just one function And a few `impl From<OtherError> for MyError` to make the try? operator work. For a library it's really not that much work. And even that can be simplified further to a few derive macros with another library : thiserror.
- asdkhadsj 6y agoTo simplify even more, you don't actually need `Display` or `Error` impls. I use Error enums frequently without display or Error impls. Though, with better backtrace support coming it'll be handy to have Error and the Backtrace related APIs implemented. (Sidenote, I don't use `impl Error` because I never use `Box<dyn Error>`. Which isn't to say that's correct, just to say that I've never had the need to implement it)
- JeanMertz 6y agoEven though GP meant to highlight compiler error messages, I also have to take my hat off for the library/application error-handling story in Rust. Using a crate such as thiserror[1] combined with displaydoc[2] makes handling errors in a structured manner a great experience. I love how the error handling story has evolved over the last couple of years in Rust, and it really feels like we're entering into the final stretch of fine-tuning to get the best possible experience. And yes, anyhow[3] is also great, it serves a different purpose, but I frequently reach for all three crates. [1]: https://crates.io/crates/thiserror https://crates.io/crates/thiserror [2]: https://crates.io/crates/displaydoc https://crates.io/crates/displaydoc [3]: https://crates.io/crates/anyhow https://crates.io/crates/anyhow
- aliceryhl 6y agoAnyhow isn't really about error handling, but about error reporting. With an ordinary enum error, I can match and easily handle the error if I want to handle some errors in special ways. If I want to handle an anyhow error, I have to do string matching on the message, or try to downcast it, which is cumbersome. What anyhow makes easier is to collect many types of errors together and reporting the errors to the user.
- pornel 6y agoIt is great. Rust 1.0 with the old borrow checker required knowing where to strategically place extra curly brackets, and when to add `ref` or `.as_ref()` incantations. Now with the smarter borrow checker and ergonomic improvements most of it is unnecessary, and the error messages know how to suggest the rest.
- metreo 6y agoStill quite a lot of circular gotchas, so it's not a panacea for studying the docs!
- madushan1000 6y agoFor an example of how good it is, I recently just renamed one go source file to .rs and rand the compiler again and again while fixing the errors it gave me and managed to get a working rust program at the end.