-
-
Notifications
You must be signed in to change notification settings - Fork 876
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
Include property name in error object #255
Comments
Possibly, duplicate of #93. |
So this is a good explanation of what is happening, but it doesn't really address the issue that, as a property level validator, this is very difficult to use. I can try and dig in and create a pull request if you'd be open to adding a property value to the error object that would provide a consistent ( between different types of errors ) user experience. |
What I was trying to explain is that you mix two different concepts here - the property of the data object in which the error happens (e.g. when you use keywords type, minimum etc.) and the property to which the error is related (when you use required, additionalProperties, dependencies) - in which case the error happens on the object level, not on the property level. dataPath points to the point in the object where the error happens. property related to error is always available in error.params. I don't think we should add one more property in error object if it doesn't add any additional information. I think it should be in the application code that processes the errors... I will think about it. In any case, the structure of error objects for all keywords is documented and it won't change, not without major version change, so you can rely on it in the code that processes errors. |
So if I understand correctly there are basically only two paths. One is On Tue, Aug 2, 2016 at 8:34 AM, Evgeny Poberezkin notifications@github.com
|
Yes, the former pointing to the parent object. What I don't like about this option is that
Kind of. I am fighting the "feature creep" here a little bit... Also I think duplicating the same information in multiple places should be at least considered carefully. As I wrote, I need to think about it...
That I agree with. I think it is (at least partially) addressed with |
Hi, yes #100 does look interesting. I'm so over booked. But if you can give me a few pointers as to where in the code I should be looking and/or where you would like to put it as well as any caveats or concerns you may have I can take a look. |
Let's keep it open for now... Re #100, you'll need to see how custom keywords that generate inline code are implemented and follow more or less the same approach. Other custom keyword types won't allow you to manipulate the array of errors. It's not too difficult, but you'll need to figure out a few things about how ajv works internally. |
@epoberezkin: why isnt The fact that PS, great job on the ajv in general! |
Because the error with Also, error has properties See above - it's explained there too. |
@reharik I was about to implement it, but stopped at naming this property of error object... The error can be both related to the object property (in which case |
I don't understand too how I can create error messages to my html forms with ajv errors. I want to write the algorithm which will be display error messages nearby with input fields, but I can't understand how it do because within error object from ajv frequently unclear to which the field can be attributed this error. I must figure out it that from And the saddest that I can't find any articles how to use ajv for displaying errors for html forms at frontend. |
This can be helpful: https://github.com/epoberezkin/ajv#validation-errors Error is always either on the property level (where you know the data path) or on the parent object level in some cases (where you know the data path as well). So you should be able to filter errors for each field. As I wrote above, you can use the option |
@epoberezkin thanks for the reply I will try to use |
This can be helpful maybe: https://github.com/DivineGod/ajv-error-messages |
It's not just required that doesn't have correct dataPath and can not be processed. Everything that is conditional, or anything that is combined from multiple schemas is complicated beyond hope, each and every time in a different way. I am actually curious if this is by design? One would assume that coming up with the same error format multiple times would be easier and more efficient than coming up different error data structures of each different situation. |
Hi, I'm passing in a schema and getting a collection of errors back. However, I need to know the property that is causing the error. In the error object, there is "dataPath" however, most of the time that value is "".
When it does show it, it is in the path notation as explained in the docs, and I would still have to parse it to get the name, but more importantly, most of the time it's blank. If it's a required field error I can dig into the "params" and get missing field, but if it's a format error then I'd have to have different logic. I suspect I'm doing something wrong, so I'm include some data.
this is what the out put of the errors array looks like, and it's in verbose, sorry trying to be thorough.
here is my json.schema
The text was updated successfully, but these errors were encountered: