hapijs / hapijs/joi

Joi schema always returns same error message from local xontext

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

Description

### Runtime

node

### Runtime version

18

### Module version

latest

### Last module version without issue

No

### Used with

standalone

### Any other relevant information

_No response_

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

Hi, I have been using Joi library latest to validate some complex schemas. And I have noticed following issue.

I have a schema stored as a string in Redis. What I do I fetch it. Then build it and use to validate some objects.

My code looks like this

```
const Joi = require('joi');
const schema = require('my-schema');

const schemaCashe = {};

if (!schemaCashe['key']) {
const joiSchema = Joi.build(schema);
schemaCashe['key'] = joiSchema
}

try {
const res = await schemaCashe['key'].validateAsync(data);
if (res.warning) {
console.log('warning', res.warning);
}
} catch (err) {
}

```

the problem that I'm having is after I validate input and If I use the local context to display the message. THe second time when I try to validate Data object. The same message is shown.

I use the custom messages like "any.only": `{#value} does not match provided `

And If I try to validate with the same object twice in a row, with data { "test": "Some text" } , and then with { "test": "Some text22" } I get twice the same message `Some textdoes not match provided `

### What was the result you got?

And If I try to validate with the same object twice in a row, with data { "test": "Some text" } , and then with { "test": "Some text22" } I get twice the same message `Some text does not match provided `

This is not valid it should always show the updated value.

### What result did you expect?

I expect the local value to be updated properly and to show the proper warning.

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.