Skip to content

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

@noinkling

Description

@noinkling

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)

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions