santhosh-tekuri/jsonschema

Panics are bad :(

Closed this issue · 7 comments

Hi! Thanks for the great library!

I started changing datapackage-go to use jsonschema and stumbled upon a panic at jsonType. That might datapackage users to crash their program, which might not be what we want.

Would that be possible to remove it (returning an error or setting a default)?

Thanks!

the panic you mentioned, only happens if jsonschema.ValidateInterface(interface{}) is used and the
value passed contains invalid json value.

for example datapackage-gojsonschema.go can cause panic if map contains any struct value

as per the documentation of jsonschema.ValidateInterface(doc interface{}):

the doc must be the value decoded by json package using interface{} type.

seems you are expecting it validate any interface{} passed.

If possible, instead of panicking, I would rather return an error if it the schema is invalid.

Thanks for the fixing it quickly!

Please consider starring the project