Skip to content
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

Custom error handler has a strange behaviour #80

Open
tomitrescak opened this issue May 24, 2019 · 2 comments
Open

Custom error handler has a strange behaviour #80

tomitrescak opened this issue May 24, 2019 · 2 comments

Comments

@tomitrescak
Copy link

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.

@tomitrescak
Copy link
Author

tomitrescak commented May 24, 2019

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' }

@tomitrescak
Copy link
Author

And this validates OK, but it should detect error on goo type:

env.validate('default', { foo: 1, boo: '2', moo: { goo: 1 } })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant