Skip to content

Custom error is ignored with multiply array items #2948

Open
@0pt1m1z3r

Description

@0pt1m1z3r

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 14.19.0
  • module version with issue: 17.9.1, 17.9.2
  • last module version without issue:
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

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

Schema:

Joi.object({
    test: Joi.array().items(
        Joi.string(),
        Joi.number()
        .custom(function(value, helpers){
            if (value===5)
                return helpers.error('test_error');
            return value;
        })
        .messages({
            'test_error': 'Test error message',
        })
    ).single(),
})

Data To Validate:

{ 
  test: 5,
}

What was the result you got?

Validation Error: "test" does not match any of the allowed types

What result did you expect?

Validation Error: Test error message

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions