hapijs / hapijs/joi

Custom error is ignored with multiply array items

Open
#2,948 3 comments 0 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### 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:
```js
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:
```js
{
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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.