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

Helpers are not passed into validation method in extends. #2170

Closed
SamJust opened this issue Oct 7, 2019 · 1 comment
Closed

Helpers are not passed into validation method in extends. #2170

SamJust opened this issue Oct 7, 2019 · 1 comment
Labels
documentation Non-code related changes

Comments

@SamJust
Copy link

SamJust commented Oct 7, 2019

Support plan

  • which support plan is this issue covered by?: Community
  • is this issue currently blocking your project?: no:
  • is this issue affecting a production system?: no

Context

  • node version: 10.15.3
  • module version with issue: 16.1.7
  • last module version without issue: -
  • environment: node
  • used with: koa v2.7.0
  • any other relevant information:

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

When extending joi, the documentation (https://hapi.dev/family/joi/?v=16.1.7#extensions) says that validate method takes helpers as 3rd argument, though undefined is passed.

const extension = (joi) => ({
    type: 'objectId',
    base: Joi.string(),
    messages: {
        'mongoId.not': '"{{#label}}" must be object Id'
    },
    validate(schema, value, helpers) {
        if (!mongoose.Types.ObjectId.isValid(value.original)) {
            return { value, errors: helpers.error('mongoId.not') }; // helpers is undefined here, an error is thrown
        }
        return { value, errors: null };
    }
});

const custom = Joi.extend(extension);

What was the result you got?

Error in the validate method "Cannot read property "error" of undefined"

What result did you expect?

A 3rd argument with helerp functions.

@SamJust SamJust added the support Questions, discussions, and general support label Oct 7, 2019
@Marsup Marsup added documentation Non-code related changes and removed support Questions, discussions, and general support labels Oct 7, 2019
@Marsup Marsup self-assigned this Oct 7, 2019
@Marsup Marsup closed this as completed in 73c3a27 Oct 7, 2019
justsml added a commit to justsml/joi that referenced this issue Oct 22, 2019
* 'master' of github.com:hapijs/joi:
  Update API.md
  Improve compile version conflict error message. Closes hapijs#2173
  Closes hapijs#2172
  Fix docs malformed code block ending at section `object.pattern.match`
  End code block
  Fix docs missing code block ending at section `date.less(date)`
  Fix function signature. Fixes hapijs#2170.
  Delete .npmrc
  Delete .editorconfig
  Delete feature_request.md
  Delete bug_report.md
  Delete CONTRIBUTING.md
  16.1.7
  Fix date format validation. Closes hapijs#2168
  16.1.6
  Closes hapijs#2165
  16.1.5
  Clarify error(). Closes hapijs#2158
  Closes hapijs#2161
  Fix handling of shadow values. Closes hapijs#2156
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Non-code related changes
Projects
None yet
Development

No branches or pull requests

2 participants