-
Notifications
You must be signed in to change notification settings - Fork 45
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
Type of error? #54
Comments
Hi @d219 The |
This only replace the error message, or I misunderstand the documentation. And it doesn't allow me to, for example, get the real type unless I check manually after getting the error. |
Sorry I did not read carefully your initial message, it's actual a good idea. I implemented in the version Example: var schema = {
type: 'object',
properties: {
lorem: { type: 'string', eq: 'ipsum' },
dolor: {
type: 'array',
items: { type: 'number' }
}
}
};
var candidate = {
lorem: 'not_ipsum',
dolor: [ 12, 34, 'ERROR', 45, 'INVALID' ]
};
var result = inspector.validate(schema, candidate, function (err, result) {
console.log(result);
}); Result: { error:
[ { code: null,
reason: 'eq',
message: 'must be equal to "ipsum", but is equal to "not_ipsum"',
property: '@.lorem' },
{ code: null,
reason: 'type',
message: 'must be number, but is string',
property: '@.dolor[2]' },
{ code: null,
reason: 'type',
message: 'must be number, but is string',
property: '@.dolor[4]' } ],
valid: false,
format: [Function: format] } If, in your |
I like that library a lot, but I have a problem with the error output. While a human readable message is fine when using it for a pet project, it become a pain to use when you have to map it to a error code.
What I mean is, I can easily know programatically which field have a error, but knowing what raised the error would involve parsing the error message, which is a horrible way, since the message could change at any time and break the system.
Would it be possible to add something like "reason" which provide the reason of the error, like "missing field", "wrong type"? I am willing to add it myself, if you could point me to where the error message is generated.
The text was updated successfully, but these errors were encountered: