hapijs / hapijs/joi

[feature] provide method by which to attach additional metadata to the returned ValidationError

Open
#2,799 0 comments 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

#### Context

```
❯ npm explain joi && node --version && uname -a
joi@17.6.0
v16.14.2
Darwin 5c52309d33e3 20.6.0 Darwin Kernel Version 20.6.0: Tue Apr 19 21:04:45 PDT 2022; root:xnu-7195.141.29~1/RELEASE_X86_64 x86_64 i386 Darwin
```

#### What problem are you trying to solve?

I need some kind of parent label that can be retrieved from the Validation Error Message. We have essentially `User.firstName` throwing an undefined (because required) error. Unfortunately `ValidationError` only provides `firstName` in the metadata, and there is no way for me to see that the root object has label `User`.

I need some way to supply to the error handler via the ValidationError the meta data `User`. I've tried `label`, `meta`, `notes`, `error()` etc. None of it carries the data, and most of it doesn't even show up in the validation error (why does it exist?).

#### Do you have a new or modified API suggestion to solve the problem?

just put things like meta and parent label, etc in the validation error details.

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.