djv
djv copied to clipboard
Custom error handler has a strange behaviour
Hello. Thanks for the cool package. I am probably not understanding something, but the customErrorHandler reports everything not just errrors. Example:
const errors = [];
const env = new djv({
errorHandler(type, tpl, m) {
errors.push({
type,
schema: this.schema[this.schema.length - 1],
data: this.data[this.data.length - 1]
});
return `;`;
}
});
env.addSchema('default', {
type: 'object',
properties: {
foo: { type: 'integer' },
boo: { type: 'string' } ,
moo: { type: 'object', properties: { goo: 'string' }, required: ['goo'] }
},
required: ['boo', 'moo']
});
env.validate('default', { foo: 1, boo: '2' })
This reports:
[ { type: 'required', schema: 'schema', data: 'data' },
{ type: 'required', schema: 'schema', data: 'data' },
{ type: 'type', schema: 'schema', data: 'data' },
{ type: 'type', schema: 'schema', data: '[\'foo\']' },
{ type: 'type', schema: 'schema', data: '[\'boo\']' },
{ type: 'required', schema: 'schema', data: '[\'moo\']' },
{ type: 'type', schema: 'schema', data: '[\'moo\']' } ]
Why is all that reported when, foo and boo are obviously correct? Thanks.
Also, with no error handler it gives only a cryptic message:
console.log(env.validate('default', { foo: 1, boo: '2' }));
result
{ keyword: 'required', dataPath: '', schemaPath: '#/required' }
And this validates OK, but it should detect error on goo
type:
env.validate('default', { foo: 1, boo: '2', moo: { goo: 1 } })