Skip to content

Missing language entry in joi.extend causes obscure runtime error #1230

@SimonSchick

Description

@SimonSchick

Context

  • node version: 7.10.
  • joi version: 10.6.0
  • environment: node
  • used with: standalone

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

const joi = require('joi');
const ourJoi = joi.extend({
    base: joi.string(),
    name: 'string',
    language: {
        // Note: Missing translation here!
    },
    rules: [
        {
            name: 'something',
            validate (params, value, state, options) {
                if (value !== '0') {
                    return this.createError('string.something', {
                        v: value,
                    }, state, options);
                }
                return value;
            },
        },
    ],
});

ourJoi.validate('test', ourJoi.string().something()); // <<<< Error Here

Which result you had ?

Upon using the rule via .validate an error gets thrown.

TypeError: Cannot read property 'length' of undefined
    at Object.toString (XXX/node_modules/joi/lib/errors.js:100:31)
    at processErrors (XXX/node_modules/joi/lib/errors.js:153:36)
    at Object.exports.process (XXX/node_modules/joi/lib/errors.js:176:22)
    at type._validateWithOptions (XXX/node_modules/joi/lib/types/any/index.js:651:31)
    at Object.root.validate (XXX/node_modules/joi/lib/index.js:121:23)

What did you expect ?

I would expect to get an error upon calling extend telling me that the language entry is required.

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions