Skip to content

Custom error handler has a strange behaviour #80

Description

@tomitrescak

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions