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

Some validation methods don't throw an error when their required argument is omitted #2729

Closed
noinkling opened this issue Jan 22, 2022 · 1 comment · Fixed by #2859
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@noinkling
Copy link
Contributor

noinkling commented Jan 22, 2022

Context

  • node version: 16.13
  • module version with issue: 17.5.0
  • last module version without issue: 15.1.1
  • environment (e.g. node, browser, native): Node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone

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

const Joi = require('joi');

Joi.string().case();  // Uncaught Error: Invalid case
Joi.string().min();  // Doesn't throw!

const { error } = Joi.string().min().validate('foo');
console.log(error.toString());  // ValidationError: "value" length must be at least  characters long

As you can see some methods that take a required argument don't throw at schema-build time, and you get a more cryptic error at validation time instead. These methods include:

  • number.greater/less/max/min/multiple
  • string.length/max/min

There are probably others.

I ran into this while trying to upgrade my v15 extensions to to the new format and trying to make sense of the behaviour when the arg assert property is specified, see here for more details: #2470 (comment)

@trizotti
Copy link
Contributor

trizotti commented Oct 6, 2022

I'm looking at this issue.

@Marsup Marsup self-assigned this Oct 13, 2022
@Marsup Marsup added the bug Bug or defect label Oct 13, 2022
@Marsup Marsup linked a pull request Oct 13, 2022 that will close this issue
@Marsup Marsup added this to the 17.6.4 milestone Oct 13, 2022
@Marsup Marsup closed this as completed Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants