-
Notifications
You must be signed in to change notification settings - Fork 33
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
Thrown error does not provide data where the validation error has happened #92
Comments
TL;DR; Would be nice to add json path to the affected node. Perhaps we could make us of inheritance (since we are dealing with a node tree (parent/child). So if JSON PathI would suggest that we "pin point" the problem with json path (rather than indexes). Error inheritanceWhen it comes to Sharing some thoughts... Since we have a tree structure, one could make use of the structure when creating error types.
|
Thanks for your suggestions! ❤️ I really like the JSON Path solution, definitely better than what I had in mind 😅 In terms of error inheritance I had the same thought and while I agree that it's probably more correct semantically I did not want to introduce a breaking change if I did not need to. It felt like error inheritance solution achieved the same goal just using a different API, so extending the original If my thought process does not make any sense pls let me know 👍 |
I really like these ideas that you guys have put forward 🙌 Here are some thoughts and questions. Having both verbose and less verbose error message sounds great! Regarding the error type/specific error classes, what purpose would this information serve and how would it be used? We type out those error messages by hand so they should be pretty useful alone, if we add JSONpath on top of that it seems to me like the error message + JSONpath will be more than enough to highlight/help to pinpoint where the error is? |
In the current implementation we're throwing errors without returning any structured data to determine where the validation error has happened. That information is being returned via the error message, which is not always ideal.
Example: A user provided a HAR config with an invalid request url.
Such a HAR config would throw
InvalidArchiveError
with amessage
ofInvalid request url (0): must be string
and with a set propertyname
equal toInvalidRequestUrl
.This implementation has a couple of issues:
The error message provides too much detail when not used in a CLI. Currently error messages almost always provide the index where the validation error happened. This probably leads to more confusion than actually helping the user if we're displaying error messages outside of a CLI.
A possible solution would be to remove the index part of the error message when validating HAR configs and only augmenting them with the index when used in a CLI.
This means the error message of our example would become:
Invalid request url must be string
Invalid request url must be string. Occurred in an entry with an index of 0.
Errors do not provide any structured data to determine where the validation error happened. Knowing where the validation error has happened would add more flexbility to the user to determine what to do with a given error.
Currently the only additional information that we provide is a
name
property (likeInvalidRequestUrl
orInvalidRequestQuery
).I'm suggesting extending the error object with two additional properties:
type
- specifies the type of validation error. Since we're validating different types of data (likerequest
,headers
,cookies
,queryString
, etc.) it would be beneficial to know the type of validation error.index
- specifies the index of validation error. Usually this property would be anumber
. In some cases it would be a tuple[number, number]
. For example, when throwing validation errors forheaders
we would like to know the indexes of both theentries
andheaders
arrays respectively. With the addition oftype
property or checking for thename
property the user will know what type to expect fromindex
.path
- pinpoints where the validation error has happened. Example:{ ..., path: 'entries[4].request.headers[0].name'}
.Let me know your thoughts on the given suggestions. Thanks!
The text was updated successfully, but these errors were encountered: