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

Incorrect documentation of validate() #2161

Closed
alxtsg opened this issue Oct 2, 2019 · 2 comments
Closed

Incorrect documentation of validate() #2161

alxtsg opened this issue Oct 2, 2019 · 2 comments
Assignees
Labels
documentation Non-code related changes

Comments

@alxtsg
Copy link

alxtsg commented Oct 2, 2019

Context

  • node version: 10.16.3
  • joi version: 16.1.4
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

I am using a schema to validate some data.

'use strict';

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

const schema = joi.object({
  name: joi.string().required(),
});

const data = {
  name: 'Alex',
};

const result = schema.validate(data);
if (result.error === null) {
  console.log('OK.');
} else {
  console.error(result.error);
}

According to the document:

If the input is valid, then the error will be null.

However, in the v16.0.0 Release Notes:

Change error in sync validate() result to undefined instead of null when there is no error (#2036).

The document is incorrect. The document should say:

If the input is valid, then the error will be undefined.

Which result you had ?

The console prints undefined.

What did you expect ?

The console should print OK.

@hueniverse hueniverse self-assigned this Oct 2, 2019
@hueniverse hueniverse added the documentation Non-code related changes label Oct 2, 2019
@hueniverse
Copy link
Contributor

Thanks. In the future, a quick PR would have been less for for both of us.

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