-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 v16: TypeError issue with valid(Joi.ref(x)).error() #2147
Comments
const schema = Joi.object().keys({
key_first: Joi.string().required(),
key_second: Joi.string().required().valid(Joi.ref('key_first'))**_.error(new Error( 'key_second must match key_first'))_**,
})
schema.validate({
key_first: 'something',
key_second: 'something else',
}, {abortEarly: false}) ===> when using Error Instance - Joi NOT returning any errors |
|
There's a related problem that error doesn't return any error, period. If I change the above example to: @hueniverse What do you think? Should we reopen this or create new issue? |
Seems to work fine for me:
And
|
I think the problem is it’s Error object rather then the object that was returned before. So it can’t be Json encoded. I return this to a client via my api and I was using error() to tweak the message |
Well, you are using it wrong. If you want to override the message, you should use
|
Ok thanks. Looking forward to using this new version now that I understand why I have these regressions |
message() didn't work because any.valid doesn't support rules.
Docs are a bit sketchy on those. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Context
What are you trying to achieve or the steps to reproduce ?
Trying to validate two fields, making sure they are the same. Use case: password + re_password fields. This worked on Joi v15 but doesn't appear to work with Joi v16.
Seems to work if I remove the error() call. The problem is item.path is undefined, and it throws an exception.
Which result you had ?
What did you expect ?
The text was updated successfully, but these errors were encountered: