-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate field type on serializing #208
Conversation
Validate each field in CBORSerializable during serialization. This will avoid bugs caused by incorrect type of field. For instance, when a field should be Address type, but being a string type instead, it would've been serialized successfully but failed to be deserialized.
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## main #208 +/- ##
=======================================
Coverage 85.59% 85.60%
=======================================
Files 26 26
Lines 2853 2882 +29
Branches 677 693 +16
=======================================
+ Hits 2442 2467 +25
- Misses 304 305 +1
- Partials 107 110 +3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Very neat! I like how this also applies to everything that is serialized very elegantly. |
I just tried this with the error I initially reported. Its a better error message for sure, but there is still some improvement possible :) builder.required_signers = ["string!"] results in
The error here is that I have a list of "str" and not list of the required type, which upsets the type checker - it fails to point out the precise violation though. I think the only reasonable fix for this would be a recursive type printer. Will look into that. |
Suggestion: Instead of printing the type of the violating object (which may hide recursive errors), just print the violating value? This also helps the developer debug, as they might have a better grip on where a value comes from than what type it has. Changes the error message to
|
Print violating field directly Co-authored-by: Niels Mündler <[email protected]>
Validate each field in CBORSerializable during serialization. This will avoid bugs caused by incorrect type of field. For instance, when a field should be Address type, but being a string type instead, it would've been serialized successfully but failed to be deserialized.
This validation also helped discovering two minor type mismatch in unit tests. 🥳