Skip to content

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

@shashankbaluni

Description

@shashankbaluni

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

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions