actix-web icon indicating copy to clipboard operation
actix-web copied to clipboard

Display field in deserialization error

Open Roms1383 opened this issue 4 years ago • 10 comments

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.

Roms1383 avatar Sep 01 '21 07:09 Roms1383

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'
Screen Shot 2564-09-01 at 14 10 40

Roms1383 avatar Sep 01 '21 07:09 Roms1383

distantly related to #73 on serde-rs/json

Roms1383 avatar Sep 01 '21 07:09 Roms1383

I end up building something like this in almost every project I use actix-web with ❤️

LukeMathWalker avatar Sep 15 '21 11:09 LukeMathWalker

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.

Roms1383 avatar Sep 21 '21 18:09 Roms1383