actix-web
actix-web copied to clipboard
Display field in deserialization error
PR Type
Feature (minor)
PR Checklist
This PR is so far, a proof-of-concept, I'd rather wait for some guidance regarding tests especially. I'll gladly add the missing parts as requested.
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] A changelog entry has been made for the appropriate packages.
- [x] Format code with the latest stable rustfmt.
- [x] (Team) Label with affected crates and semver status.
Overview
Currently, when deserialization error happens in either Json or Query, there's no hint at the field which caused it.
As of now, given an expected limit i32 field in query string parameters, and provided with an incorrect String :
e.g. Query deserialize error: invalid digit found in string
This PR add a new feature beautify-errors (actix contributors please suggest a better name, and if a feature is the right solution), which will turn the same error out to :
e.g. Query deserialize error: 'limit': invalid digit found in string
Not sure if this closes issue(s) or not.
As a side note I currently added error to the examples, with a postman collection to allow for quickly trying.
RUST_BACKTRACE=1 RUST_LOG=debug cargo watch -x 'run --example error'
distantly related to #73 on serde-rs/json
I end up building something like this in almost every project I use actix-web with ❤️
Just realized I actually shouldn't have merged the changes while the PR is opened, let me know if you want me to open another one fresh from start. Also, adding a new feature from such a minor change is probably not worth it, let me know if you would like me to implement it differently.