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

Request: Warn when functions are passed unexpected arguments #1009

Closed
ltegman opened this issue Oct 17, 2016 · 7 comments
Closed

Request: Warn when functions are passed unexpected arguments #1009

ltegman opened this issue Oct 17, 2016 · 7 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@ltegman
Copy link

ltegman commented Oct 17, 2016

Context

  • node version: 4.X
  • joi version: 9.0.4
  • environment (node, browser): node
  • used with (hapi, standalone, ...): hapi
  • any other relevant information:

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

We had a developer, who after working with Joi.object for a couple validations assumed that Joi.string would also have a default behavior when passed an argument (this default behavior being to enforce a max). I realize this assumed behavior is not documented anywhere, but I think it would be nice if Joi.string and other similar validators that don't accept an argument would warn you of that if you pass them something.

const schema = {
  messageText: Joi.string(1024).required()
};

Which result you had ?

Joi.string silently accepted the argument, doing nothing with it.

What did you expect ?

A Joi error indicating that Joi.string does not accept any arguments

@Marsup
Copy link
Collaborator

Marsup commented Oct 18, 2016

This seems like a pretty random assumption, why max ? Will take a PR including all the types.

@ar4mirez
Copy link
Contributor

ar4mirez commented Dec 3, 2016

guys I got some free time if none of you is working on this PR I'm available to work on this one, lmk.

@AdriVanHoudt
Copy link
Contributor

@ar4mirez feel free to submit a PR!

@ar4mirez
Copy link
Contributor

ar4mirez commented Dec 4, 2016

Guys quick question I have a solution done for the first level types any(), array(), binary(), boolean(), date(), number(), string(), so my question is do you guys want to apply the same enhancement to second level types such as required(), forbidden() etc... ?

Thanks.

@Marsup
Copy link
Collaborator

Marsup commented Dec 4, 2016

Not for now, most inputs are validated or mistakes can't be avoided.

@ar4mirez
Copy link
Contributor

ar4mirez commented Dec 4, 2016

Alright make total sense to me, I'll PR then what I have and receive your feedback.

@Marsup Marsup self-assigned this Dec 4, 2016
@Marsup Marsup added this to the 10.0.3 milestone Dec 4, 2016
@Marsup Marsup closed this as completed Dec 4, 2016
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@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
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

5 participants