{"id":"07e0717b38b5f659","repo":"sequelize/sequelize","slug":"invalid-validator-function-validatortype","errorCode":null,"errorMessage":"Invalid validator function: ${validatorType}","messagePattern":"Invalid validator function: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/instance-validator.js","lineNumber":353,"sourceCode":"\n  /**\n   * Prepare and invoke a build-in validator.\n   *\n   * @private\n   *\n   * @param {*} value Anything.\n   * @param {*} test The test case.\n   * @param {string} validatorType One of known to Sequelize validators.\n   * @param {string} field The field that is being validated\n   *\n   * @returns {object} An object with specific keys to invoke the validator.\n   */\n  async _invokeBuiltinValidator(value, test, validatorType, field) {\n    // Cast value as string to pass new Validator.js string requirement\n    const valueString = String(value);\n    // check if Validator knows that kind of validation test\n    if (typeof Validator[validatorType] !== 'function') {\n      throw new TypeError(`Invalid validator function: ${validatorType}`);\n    }\n\n    const validatorArgs = this._extractValidatorArgs(test, validatorType, field);\n\n    if (!Validator[validatorType](valueString, ...validatorArgs)) {\n      throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), {\n        validatorName: validatorType,\n        validatorArgs,\n      });\n    }\n  }\n\n  /**\n   * Will extract arguments for the validator.\n   *\n   * @param {*} test The test case.\n   * @param {string} validatorType One of known to Sequelize validators.\n   * @param {string} field The field that is being validated.","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/sequelize/sequelize/blob/7e1deec499d5afbb8d1877c2f4d545cead1214ec/packages/core/src/instance-validator.js#L335-L371","documentation":"In `_invokeBuiltinValidator` (instance-validator.js:348), Sequelize resolves each attribute validator by name against the validator.js `Validator` object. If `typeof Validator[validatorType] !== 'function'` (instance-validator.js:352), the declared key is neither a recognized built-in validator nor a custom function (custom functions are handled earlier in `_singleAttrValidate`), so it throws a TypeError. This catches misspelled validator names and non-function values placed under an attribute's `validate` object.","triggerScenarios":"Defining an attribute with `validate: { isEmial: true }` (typo), `validate: { myRule: 'yes' }` (string value with a key that is not a validator.js method), or any non-function value whose key does not exist on validator.js's Validator.","commonSituations":"Typos in built-in validator names (isEmial vs isEmail, notEmpty vs notempty); copy-pasting a custom validator name but forgetting to make the value a function; mismatched validator.js version that renamed/removed a method.","solutions":["Check the validator name spelling against the validator.js method list (isEmail, isUrl, notEmpty, isInt, len, etc.).","If the validator is custom, make its value a function: `validate: { myRule(value) { ... } }`.","Confirm the validator.js version bundled with your Sequelize release still exposes that method."],"exampleFix":"// before\nemail: { type: DataTypes.STRING, validate: { isEmial: true } }\n\n// after\nemail: { type: DataTypes.STRING, validate: { isEmail: true } }","handlingStrategy":"type-guard","validationCode":"import validator from 'validator';\n\nfunction assertValidAttributeValidators(validateObj) {\n  for (const [name, spec] of Object.entries(validateObj || {})) {\n    if (typeof spec === 'function') continue; // custom validator ok\n    if (typeof validator[name] !== 'function') {\n      throw new Error(`Unknown built-in validator '${name}'. Fix the name or make it a function.`);\n    }\n  }\n}\n\n// run before Model.init\nassertValidAttributeValidators(attrDef.validate);","typeGuard":"function isKnownValidator(key, val) {\n  return typeof val === 'function' || typeof validator[key] === 'function';\n}","tryCatchPattern":null,"preventionTips":["Cross-check built-in validator names against the validator.js documentation shipped with your Sequelize version.","Always declare custom validators as functions, never as objects/strings.","Add a unit test that asserts every attribute validate key resolves to a function or a validator.js method."],"tags":["validation","schema","config"],"analyzedSha":"7e1deec499d5afbb8d1877c2f4d545cead1214ec","analyzedAt":"2026-08-03T18:58:44.549Z","schemaVersion":2}