You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a case where an invalid schema was used that had an enum property with the array undefined. JaySchema didn't throw an exception or invoke the callback.
Here's a quick example to illustrate the problem:
varJaySchema=require('jayschema');varinstance="hello";varschema={enum : undefined};functionloader(ref,callback){console.log('loader referenced');callback('The schema referenced, '+ref+', could not be found.');}varjs=newJaySchema(loader);// if no loader is specified I get a synchronous exceptionjs.validate(instance,schema,function(errs){if(errs){console.error('async validation failed!',errs);}// never calledelse{console.log('async validation OK!');}// also never called});console.log('validation started');
With 0.3.1 I get a stack trace on the console, but with 0.2.7 I didn't get anything at all (so at least that's an improvement).
The text was updated successfully, but these errors were encountered:
Unfortunately the schema itself does not get validated.
The original thinking was that schemas would be valid/tested so validating the schema itself would not be worth the performance hit. But JaySchema strives for correctness, even at the expense of speed, and it’s obviously not cool to throw there. So that may have to change (or have automatic schema validation be an option in a future version).
In the meantime, you can do something like this to validate the schema before validating the instance:
Thanks Nate. I'll add in calls to validate like you mentioned.
Would it make sense to add some generic error handling around the
validation method in Jayschema so the callback could at least be invoked
with something like "Unexpected error"?
Unfortunately the schema itself does not get validated.
The original thinking was that schemas would be valid/tested so validating
the schema itself would not be worth the performance hit. But JaySchema
strives for correctness, even at the expense of speed, and it’s obviously
not cool to throw there. So that may have to change (or have automatic
schema validation be an option in a future version).
In the meantime, you can do something like this to validate the schema
before validating the instance:
I ran into a case where an invalid schema was used that had an enum property with the array undefined. JaySchema didn't throw an exception or invoke the callback.
Here's a quick example to illustrate the problem:
With 0.3.1 I get a stack trace on the console, but with 0.2.7 I didn't get anything at all (so at least that's an improvement).
The text was updated successfully, but these errors were encountered: