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

Make the DataTypeError thrown when dealing with types make more sense #17

Open
bytesnz opened this issue Feb 10, 2016 · 0 comments
Open
Assignees
Milestone

Comments

@bytesnz
Copy link
Member

bytesnz commented Feb 10, 2016

The DataTypeError thrown when the data is found not to match any of the allowed types doesn't make any sense. Given the test file

var skemer = require('skemer');

var schema = {
  types: {
    array: {
      type: 'string',
      multiple: true
    },
    object: {
      types: {
        array: {
          type: 'string',
          multiple: true
        }
      },
      multiple: true,
      object: true
    }
  }
};

console.log(skemer.validateNew({ schema: schema }, [ 'test', 'test1' ]));

console.log(skemer.validateNew({ schema: schema }, {
  'test': ['test', 'test2'],
  'test2': ['test', 'test3']
}));

try {
console.log(skemer.validateNew({ schema: schema }, {
  'test': ['test', 'test2'],
  'test2': 'dsfds'
}));
} catch(err) {
  console.log(err);
}

try {
console.log(skemer.validateNew({ schema: schema }, {
  'test': ['test', 'test2'],
  'test2': ['test', 42]
}));
} catch(err) {
  console.log(err);
}

the output is

[ 'test', 'test1' ]
{ test: [ 'test', 'test2' ], test2: [ 'test', 'test3' ] }
{ [DataTypeError: object value is not allowed for test2]
  name: 'DataTypeError',
  message: 'object value is not allowed for test2',
  extra: 
   { schema: { types: [Object] },
     baseSchema: { types: [Object] },
     newData: { test: [Object], test2: 'dsfds' },
     data: undefined } }
{ [DataTypeError: object value is not allowed for test2]
  name: 'DataTypeError',
  message: 'object value is not allowed for test2',
  extra: 
   { schema: { types: [Object] },
     baseSchema: { types: [Object] },
     newData: { test: [Object], test2: [Object] },
     data: undefined } }

The error message should something like the value given for ____ does not match any of the specified types and should include as extra data the errors that were thrown by each type failure.

@bytesnz bytesnz self-assigned this Feb 10, 2016
@bytesnz bytesnz added this to the 0.9.0 milestone Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant