Feature/improved failure handling experience #331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
I have 2 ideas (and ready implementations in this PR) to improve error message readability.
The first idea
I often encounter is overly detailed logging of complex structures in the "Expected" messages.
For example:
let's have this schema
The validation result will be very messy:
It seems unnecessary to describe the expected type since it is already known in the runtypes schema description. Moreover, this description complicates error message readability.
Instead, I propose writing "Expected (array | tuple | object | dictionary) but was ..."
in this PR result will change to this
It looks readable and doesn't lose its meaning.
The second idea
In messages like "Expected something but was (array | object)" it would be helpful to see exactly which entity was received.
I have decided to add a new field called
extraDetails
next to thedetails
field, which will contain not only the error message but also the actual value (received
field) and possibly the error code.Let's go back to the previous schema and pass it this object as input:
In this PR, the
result.extraDetails
field will contain this convenient message:Thus,
extraDetails
will improve error perception without affecting the existingdetails
field.