qri-io / jsonschema

golang implementation of https://json-schema.org drafts 7 & 2019-09
MIT License
461 stars 54 forks source link

need better error messages for invalid jsonschemas #28

Open b5 opened 6 years ago

b5 commented 6 years ago

Yesterday I made a bonehead mistake & wrote something like the following schema:

{
  "type" : "array",
  "fields": {
    "type" : "array",
    "fields": [
      { "name" : "foo", "type": "array", "extraField": "foobar" }
    ]
  }
}

So, uh there's a bunch of things wrong with ☝️

The error returned gave me zero indication of how to fix the schema. This was in the context of adding data to qri, where problems can arise in a number of places, which sent me off hunting for bugs that didn't exist.

While I don't expect the returned error to catch something like "blah should actually be a blah field", jsonschemas can become quite large documents, so I'd like to upgrade parsing a jsonschema error returns to do two new things:

By "independant of go syntax", I mean we should try to say things like: fields is not a valid jsonschema validator and once I fix the first "fields" (but not the second), it'd be great if items.fields is not a valid jsonschema validator and when that's fixed: items.fields.name is not a valid jsonschema validator, etc.

handrews commented 6 years ago

You might be interested in the discussion going on at https://github.com/json-schema-org/json-schema-spec/issues/396 regarding possibly adding a recommended output/error format to the specification. Difficulty with error reporting has become a very common complaint across implementations.

handrews commented 4 years ago

Note that a set of output format recommendations did make it into the latest draft.