joi icon indicating copy to clipboard operation
joi copied to clipboard

Improve error message

Open catalint opened this issue 10 years ago • 6 comments

"use strict"

const Joi = require('joi')

const moves = {
    like: 'jagger',
    true: 'maybe'
}

const def = Joi.object({
    true: Joi.string().valid('maybe')
})


// OK
console.log(String(def.validate(moves).error))
// ValidationError: "like" is not allowed

// NOT OK
console.log(String(def.label('Moves').validate(moves).error))
// ValidationError: "Moves" is not allowed

// EXPECTED

// ValidationError: "like" is not allowed for "Moves"
// OR AT LEAST
// ValidationError: "like" is not allowed

catalint avatar Jan 28 '16 18:01 catalint

Root can't really have a label since it doesn't have a name in javascript, there's no path to access it.

Marsup avatar Jan 28 '16 19:01 Marsup

Don't really understand what you are referring to as root and the fact that it doesn't have label?

The above code works, and the validation is wotking also, but the error generated now is missleading if the object has a label.

Can you confirm the issue?

catalint avatar Jan 28 '16 20:01 catalint

I see, misinterpreted your report, it's already been fixed in 7.2.2, which version are you running ?

Marsup avatar Jan 28 '16 22:01 Marsup

Unfortunately I'm using 7.2.2 and seeing this

catalint avatar Jan 29 '16 07:01 catalint

Confirmed, I'll fix it in a while, just noticed 7.2.2 actually introduced a bug.

Marsup avatar Jan 29 '16 12:01 Marsup

thanks !

catalint avatar Feb 01 '16 11:02 catalint