Skip to content

Possible bug in custom Error message #1144

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

Closed
ozum opened this issue Mar 31, 2017 · 3 comments
Closed

Possible bug in custom Error message #1144

ozum opened this issue Mar 31, 2017 · 3 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@ozum
Copy link

ozum commented Mar 31, 2017

Context

  • node version: 7.7.1
  • joi version: 10.3.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

I try to have a custom error message if a parameter is required conditionally and it is not provided in input. For example for the schema below at least one of the start or match parameters should be provided. So I made start required if match is not provided, and I want to tell user, that one of them should be provided instead of start is required..

const schema = {
  ignore: Joi.array().items(Joi.string()).optional(),
  types: Joi.object().pattern(/\w+/, Joi.array().items(Joi.string())).optional(),
  rules: Joi.array().items(Joi.object().keys({
    type: Joi.string(),
    start: Joi.array().items(Joi.string()).when('match', { is: Joi.empty(), then: Joi.required().error(new Error('CUSTOM MESSAGE')), otherwise: Joi.optional() }),
    match: Joi.alternatives().try(Joi.string(), Joi.object().type(RegExp)).optional(),
  })),
};

const config = {
  ignore: ['space'],
  types:  {
    identifier:  ['select'],
    conjunction: ['and', 'or'],
  },
  rules: [
    { type: 'sil' },
  ],
};

  Joi.assert(config, schema);

Which result you had ?

Exception is thrown for:
TypeError: error.annotate is not a function

What did you expect ?

I expected my custom exception:
CUSTOM MESSAGE

@ozum ozum changed the title Possible Bug in custom Error message Possible bug in custom Error message Mar 31, 2017
@Marsup Marsup self-assigned this Mar 31, 2017
@Marsup Marsup added the bug Bug or defect label Mar 31, 2017
@Marsup Marsup closed this as completed in 4e7914c Mar 31, 2017
@Marsup Marsup added this to the 10.3.2 milestone Mar 31, 2017
@Marsup
Copy link
Collaborator

Marsup commented Mar 31, 2017

Published.

@Marsup
Copy link
Collaborator

Marsup commented Mar 31, 2017

Maybe talked too fast, another 10.3.3 is coming.

@Marsup
Copy link
Collaborator

Marsup commented Mar 31, 2017

Done.

@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