Skip to content

labels don't always get included in error messages with Joi.extend() #929

@MarkHerhold

Description

@MarkHerhold

Context

  • node version: 6.2.1
  • joi version: 9.0.0-5
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone

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

Here's an example of a test Joi extension that always produces an error.

let Joi = require('joi@9.0.0-5');
Joi = Joi.extend({
        base: Joi.any(),
        name: 'any',
        language: {
            anytest: 'is a test'
        },
        rules: [{
            name: 'anytest',
            validate(params, value, state, options) {
                return this.createError('any.anytest', { v: value }, state, options); // always creates an error
            }
        }]
    });

Joi.any().anytest().label('myString').validate('foo');

Which result you had ?

The above produces an error object with: Error: "value" is a test

What did you expect ?

I expected the label to be included in the error message: Error: "myString" is a test

Native Joi example of what I expected:

This native Joi example produces what I would expect:

Joi.string().label('myString').validate(1)

✅ Produces Error: "myString" must be a string

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions