-
Notifications
You must be signed in to change notification settings - Fork 100
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
Feature: formating of errormessages for display to end user #44
Comments
I'm trying to do something similar. So when I get something like:
I ultimately want to access the "title" or "description" field of the Is there a way to fetch the Schema based on the |
Are there any tools or helper functions to do this? I looked into the code but didn't find anything close. I see you've https://github.com/santhosh-tekuri/xpath but I don't have a remote idea on how that can parse a JSON Schema. Any pointers to dig deeper? |
sorry. not xpath. as jsonpath you split it by so golang navigation for keywordLocation
|
you can find some sample code here the sample code works on json objects like map/interface. in your case you have to do it for |
@santhosh-tekuri Thank you for your response here. Your commentary was very helpful for me to arrive at a solution. |
Hello @santhosh-tekuri, What do you think to implement only one string per error and custom error with templating like https://github.com/xeipuuv/gojsonschema? (This lib seems unmaintened...) It will be a great feature 👍 |
hi @santhosh-tekuri, thanks for your great work first. I'd like to vote on the api, with an api to get the |
hi @santhosh-tekuri,I have a similar situation here,I hope there has a interface that i can define custom error template,did you have plan to support it? |
Started working on this feature. Will post pull request tomarrow |
please check pull request #99 go through the changes and let me know your opinion |
fix available in |
Hi everyone, I too had a similar case where I didn't want to use https://github.com/xeipuuv/gojsonschema because it seemed unmaintained but I liked the more actionable format for users. I ended up implementing a way to get a similar format to what https://github.com/xeipuuv/gojsonschema does but with this package. The below function returns error strings that look like the below block. In this case the schema had two things wrong with it and we got the following two entries in the returned array. @santhosh-tekuri If you'd like I can make a PR adding this function to be built into the package, I think many would find it useful.
func getChildCauses(validationErr *jsonschema.ValidationError, childCauses []error) []error {
if validationErr == nil {
return childCauses
}
if validationErr.Causes == nil {
errMessage := fmt.Errorf(" - %s: %s", validationErr.InstanceLocation, validationErr.Message)
return append(childCauses, errMessage)
}
for _, subCause := range validationErr.Causes {
childCauses = getChildCauses(subCause, childCauses)
}
return childCauses
} |
Hi 👋 Thank you for this lovely package, dropping an example from a JavaScript package (AJV) for https://ajv.js.org/packages/ajv-errors.html#messages-for-properties-and-items. I know that it's not "proper" JSON schema, but I think that in some cases it can be quite hard for the underlying validation library to provide a user friendly error message. A common example is using patterns to validate strings. The underlying library can mostly error out with Other examples can be usage of |
#### Summary Fixes cloudquery/cloudquery-issues#1526 (internal issue). This PR uses the custom errors syntax from https://ajv.js.org/packages/ajv-errors.html#messages-for-properties-and-items to improve the errors we provide for the S3 destination plugin (and aligns file and GCS plugin with it). While this won't help with the Go validation until santhosh-tekuri/jsonschema#44 is implemented it does help with our Cloud Syncs, examples below. The `errorMessage->properties->prop-name` is needed so the UI knows to show the error under the correct field and not as a top level error Before: ![image](https://github.com/cloudquery/cloudquery/assets/26760571/e5d252a1-5ca5-4650-bde8-ce1b79960eb0) After: ![image](https://github.com/cloudquery/cloudquery/assets/26760571/3de97312-eaf3-4230-bb3b-cf20aebed0c2) Before: ![image](https://github.com/cloudquery/cloudquery/assets/26760571/10a0da89-8f1c-4620-adfd-532832915b99) After: ![image](https://github.com/cloudquery/cloudquery/assets/26760571/2945a600-1fc0-4e08-9ee2-b139c0d90a5d) (The latter still need some frontend work not to show the top level error)
Hello, I'm exploring JSON Schema validation (in particular the UX of it) at the moment. I started with https://github.com/xeipuuv/gojsonschema and like others, was concerned about its apparent lack of maintenance, and have arrived here. The CLI validation output is nice, but can still be rather impenetrable for mere mortals. I'm validating the OSV Schema:
I had high hopes of being able to judiciously insert some |
simple since you can get schemaLocation for validationError, from schemaLocation you can extract your custom error message. |
My feedback was more on the From further research:
So it sounds like there's an opportunity to be utilizing I played around with andrewpollock/osv-schema@a923795 and andrewpollock/osv-schema@cf4d326 but the addition of |
what I meant is if you want to use them for errors, you may have to modify the tool |
I'm trying to figure out how
jsonschema.ValidationError
are to be translated to something understandable to an end user, or for that matter looped to for example mark input fields for the error.I get string like "additioalProperties 'test1', 'test2', 'test3' is not allowed" or "missing properties: 'firstName'". and no separate field to check the list of the fields with the error or what a machine understandable version of the error is.
Am I missing something or isn't there a way to do anything except showing the result as a string blob?
The text was updated successfully, but these errors were encountered: