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

In case custom error messages are passed to Joi.any.error, joi.validate returning parent object error even if child validation fails. #1219

Closed
shashankbaluni opened this issue Jun 13, 2017 · 3 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@shashankbaluni
Copy link

Context

  • node version: 4.4.2
  • joi version: 10.5.5
  • environment (node, browser):node
  • used with (hapi, standalone, ...):standalone
  • any other relevant information: Passing custom error instance to Joi().any().error()

What are you trying to achieve or the steps to reproduce ?

Describe your issue here, include schemas and inputs you are validating if needed.

const Joi = require('joi');

const addressSchema = Joi.object().keys({
  address: Joi.object().keys({
    pin: Joi.number()
      .min(100000)
      .max(999999)
      .error(new Error('pincode is missing'))
      .required()
  }).error(new Error('address is missing'))
.required()
});

let address ={
  "action" : "xyz",
    "address": 
  {
    "id": "1",
      "title": 'Home'
  }
}

Joi.validate(address, addressSchema, (err, value) => console.log(err));

Which result you had ?

address is missing

What did you expect ?

pincode is missing

@shashankbaluni shashankbaluni changed the title In case of custom error messages passed Joi.any.error, joi.validate returning parent object error even if child validation fails. In case custom error messages are passed to Joi.any.error, joi.validate returning parent object error even if child validation fails. Jun 13, 2017
@Marsup Marsup added the request label Jun 13, 2017
@santosh-gupta11
Copy link

Any updates on this issue.

@Marsup
Copy link
Collaborator

Marsup commented Dec 20, 2017

No, this is very far from being a priority and behaves as described in the docs. I should probably close it as I don't think it needs fixing.

@Marsup Marsup self-assigned this Jun 15, 2018
@Marsup Marsup closed this as completed Jun 15, 2018
@Marsup Marsup added this to the 14.2.0 milestone Nov 25, 2018
@hello2dj
Copy link

why

@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

5 participants