5 ms·
The question-mark shorthand (?) basically does what the blog post is describing, and makes a lot of this stuff straightforward. There _is_ some futzing that so
by rtpg 3y ago
The question-mark shorthand (?) basically does what the blog post is describing, and makes a lot of this stuff straightforward.
There _is_ some futzing that sometimes have to happen due to various operations' Result types using incompatible Error types. That's just a thing that has to be dealt with.
- mcronce 3y agoYeah, but that futzing typically happens separately near the "outer" error type's declaration - and when it doesn't, a concise .map_err() often does the job. It's also often taken care of by a sort thiserror macro invocation per "inner" type. There are obviously more complex error setups, but this covers the vast majority IME
- rtpg 3y agoI get why it's like this but I have often found that most of the time code ends up bailing by using a conversion into `String` quite quickly, leading to everything being stringified anyways. I get why this is, but it does make me miss the Python Exception model of "there's ~15 base exception types. One of them is probably good enough for you". One could point out that the arguments are usually "just" strings there too, but at least there's some conventions. I understand Rust's philosophy, I just find it annoying.
- mcronce 3y agoI haven't experienced that at all. Any of the codebases I've worked in - both proprietary and open-source - have converted errors to strings when it becomes necessary: When presenting it to a user, whether that means logging or placing it in an HTTP response body, etc.
- _AzMoo 3y agoI find Rust's question mark shorthand and the resulting futzing you're talking about adds a lot more cognitive load for me than Go's verbose if err conventions. I think more than anything this kind of syntactical discussion is just very subjective.
- rtpg 3y agoIt's definitely subjective! I think the `?` stuff in itself is pretty straightforward for a DSL-like behavior. The futzing from when you're mixing actions from multiple codebases is unfun.
- threeseed 3y agoThat last point can also be considered a feature. Being able to define your own app-specific Error type which everything gets converted to is incredibly useful and powerful. Especially for web apps where you can return the correct response codes depending on the error.