Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MarkHerhold opened this issue Jun 18, 2016 · 3 comments
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@MarkHerhold
Copy link

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

@Marsup Marsup added the bug Bug or defect label Jun 18, 2016
@Marsup Marsup added this to the 9.0.0 milestone Jun 18, 2016
@Marsup Marsup self-assigned this Jun 18, 2016
@Marsup
Copy link
Collaborator

Marsup commented Jun 18, 2016

Good spotting @MarkHerhold, fixing now.

@Marsup Marsup closed this as completed in 55dc1e1 Jun 18, 2016
@Marsup
Copy link
Collaborator

Marsup commented Jun 18, 2016

Released as 9.0.0-6.

@MarkHerhold
Copy link
Author

Thanks @Marsup!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants