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

Joi.array().items(...) error message changes #589

Closed
DavidTPate opened this issue Mar 5, 2015 · 5 comments
Closed

Joi.array().items(...) error message changes #589

DavidTPate opened this issue Mar 5, 2015 · 5 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@DavidTPate
Copy link
Contributor

Going through the new 6.0 release it looks like the error messages for Array items have actually gotten worse now. So instead of receiving an error such as: value at position 0 fails because value length must be less than or equal to 5 characters long assuming that we have a schema such as:

var schema = Joi.array().includes(Joi.string().min(5).required());

Now when we have a schema such as:

var schema = Joi.array().items(Joi.string().min(5).required());

The same array being validated which doesn't have the minimum 5 characters just results in an error stating "value" does not contain 1 required value(s). Is there are particular constraint to the change to items() which resulted in these error messages being less useful or do the error messages just need to be enhanced?

Thanks!

@AdriVanHoudt
Copy link
Contributor

I had the same error earlier with the same thought. The error does say what is wrong (sort of) with the array (the value, the array, is missing a required item) but it would be nice to propagate deeper error messages. Saying value length must be less than or equal to 5 characters long is way better than the array error.
That being said it probably has something to do with Joi only taking action when something goes right but not throwing when going wrong see roughly https://github.com/hapijs/joi/blob/master/lib/array.js#L151

If someone can point me in the right direction I might do a PR

@Marsup
Copy link
Collaborator

Marsup commented Mar 5, 2015

Required has a meaning now, remove it from that string and you'll get back your old message.

@Marsup Marsup added the non issue Issue is not a problem or requires changes label Mar 5, 2015
@Marsup Marsup self-assigned this Mar 5, 2015
@Marsup Marsup closed this as completed Mar 5, 2015
@AdriVanHoudt
Copy link
Contributor

Why does array not follow the same logic as object().keys()? If a key, with required() on it, fails it tells you why [ValidationError: child "email" fails because ["email" must be a valid email]] it would be weird to have it state just object does not contain 1 required key.
The array error could be value at position x fails because [deepest error to help pinpoint]?

@Marsup Marsup added bug Bug or defect and removed non issue Issue is not a problem or requires changes labels Mar 5, 2015
@Marsup Marsup added this to the 6.0.3 milestone Mar 5, 2015
@Marsup Marsup reopened this Mar 5, 2015
@Marsup Marsup closed this as completed in 3e7f675 Mar 5, 2015
@AdriVanHoudt
Copy link
Contributor

👍

@DavidTPate
Copy link
Contributor Author

Thanks @Marsup 👍

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

3 participants