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

Cannot read property 'delete' of undefined #2165

Closed
i3fox opened this issue Oct 4, 2019 · 1 comment
Closed

Cannot read property 'delete' of undefined #2165

i3fox opened this issue Oct 4, 2019 · 1 comment
Assignees
Labels
bug Bug or defect
Milestone

Comments

@i3fox
Copy link

i3fox commented Oct 4, 2019

With the update to version 16.1.5 I have an exception.

With version 16.1.4 it works correctly.

Context

  • node version: 10.16.3
  • joi version: 16.1.5
  • environment: node

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

const Joi = require('@hapi/joi');

const itemsSchema = Joi.object().pattern(Joi.string(), Joi.object({
  res: Joi.string(),
  params: Joi.object({
    custom: Joi.string().when('...res', {
      is: 'custom',
      then: Joi.required(),
      otherwise: Joi.any().strip(),
    }),
  }),
}));

const data = {
  item1: {
    res: 'automatic',
    params: {
      custom: 'x',
    },
  },
  item2: {
    res: 'manual',
    params: {
      custom: 'y',
    },
  },
};

itemsSchema.validate(data);

Which result you had ?

TypeError: Cannot read property 'delete' of undefined
at internals.Shadow.override (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/state.js:147:20)
at module.exports.internals.State.restore (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/state.js:63:34)
at internals.Base.$_match (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:662:15)
at internals.Base._generate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:835:24)
at Object.exports.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/validator.js:163:25)
at internals.Base.$_validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:751:26)
at Object.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/types/keys.js:107:45)
at Object.exports.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/validator.js:314:26)
at internals.Base.$_validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/base.js:751:26)
at Object.validate (/home/deop/Workspaces/test/node_modules/@hapi/joi/lib/types/keys.js:107:45)

What did you expect ?

{
  item1: {
    res: 'automatic',
    params: {
    },
  },
  item2: {
    res: 'manual',
    params: {
    },
  },
};
oskar-kupski-elpassion added a commit to oskar-kupski-elpassion/joi that referenced this issue Oct 4, 2019
@hueniverse hueniverse self-assigned this Oct 4, 2019
@hueniverse hueniverse added the bug Bug or defect label Oct 4, 2019
@hueniverse hueniverse added this to the 16.1.6 milestone Oct 4, 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
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants