aws-sdk-rust: [guide section]: Error handling
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or “me too” comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue, please leave a comment
Tell us about your request Add guide section around error handling best practices
- handling unknown
- extracting error messages
- using
is_xyz()error check methods - converting to top-level service errors
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 51
- Comments: 15 (9 by maintainers)
I think it would be nice to have complete examples of error handling as a part of the regular documentation. Right now the documentation doesn’t cover any form of error handling at all.
@fnordpig - Thank you for the feedback! I agree with what you’re saying, and we definitely have room to improve here. The next SDK release will at least improve the error handling situation slightly, which you can read about in #657. We’re also thinking about combining the
ErrorandErrorKindtypes to further simplify error handling, which you can read about and provide feedback for in this RFC.Thanks! By the way, I love the SDK. Thanks for all the work you guys are doing!
@jdisanti Yes the proposal makes sense. I learned something about rust from your examples provided as well. You guys should provide more examples in the documentation for how to handle errors! Like a cookbook. But reading through your first example it showed me how they’re intended to be used, which makes a lot more sense and would have saved a lot of trouble.
Hello! All errors actually
impl Into<aws_sdk_blahblah::Error>which is a top-level error generated for each service. This combines the error variants of all operations into a single error to simplify error handling.If you match against this error, it will look at lot more like what you expect: https://docs.rs/aws-sdk-dynamodb/0.6.0/aws_sdk_dynamodb/enum.Error.html
The primary intention here is that you might have something like:
but you can also use this to simplify error handling in general when you don’t care handling different failure modes
I just was about to file a request to this vein. I found myself writing the following in order to test against whether a DynamoDB request failed due to the conditional request or not:
Clearly this isn’t exactly pleasant nor legible. After noting the issue I did find a slightly better method but it’s only slightly better.
I think the larger issue here is the errors don’t “feel” Rust-like. It’d be my expectation that instead of being returned a complex nested series of
enums andstructs holding the error type, I should instead be able to write something as simple asAnd go about my day. This is just my own way of thinking though and it may be way off-base.