hapijs / hapijs/joi

Custom validators recieve an unresolved promise when asynchronously validating.

Open
#2,571 1 comment 0 reactions 0 assignees View on GitHub
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): no
* *is this issue affecting a production system?* (yes/no): no
#### Context

* *node version*: 15.7.0
* *module version*: 17.4.0
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): custom framework
* *any other relevant information*:

#### How can we help?

```js
const joi = require('joi');

joi
.string()
.custom((v) => v.slice(1))
.custom(
async (v) =>
await new Promise((res) => setTimeout(res, 10000, v.toUpperCase()))
)
.custom(
async (v) => await new Promise((res) => setTimeout(res, 10000, v, 'b'))
)
.validateAsync('foobar')
.then(console.log)
.catch(console.error);
```

The thrid custom validator recieves an unresolved promise (current workaround `v=await v; ...`)

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.