From 68f41e945fd06ab552abe821149bedfd6baeb235 Mon Sep 17 00:00:00 2001 From: Benjamin Pannell Date: Tue, 3 Dec 2013 01:20:45 +0200 Subject: [PATCH] Improve error messages for validation of missing values --- lib/utils/validation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/validation.js b/lib/utils/validation.js index 7b4efcb..09fca29 100644 --- a/lib/utils/validation.js +++ b/lib/utils/validation.js @@ -66,7 +66,7 @@ var validateType = (require.modules || {}).validation = module.exports = functio if (!schemaType) return pass; - if (schemaType === true) return assert(value, 'value'); + if (schemaType === true) return assert(value, 'value', value || 'nothing'); if (schemaType === Object) return pass; if (_.isPlainObject(schemaType)) { @@ -114,6 +114,6 @@ var validateType = (require.modules || {}).validation = module.exports = functio if (schemaType === Number) return assert(_.isNumber(value), 'number'); if (schemaType === Boolean) return assert(_.isBoolean(value), 'boolean'); if (schemaType === Date) return assert(_.isDate(value), 'date'); - if (schemaType instanceof RegExp) return assert(schemaType.test(value), 'regex ' + schemaType.toString() + ' to match', value.toString()); + if (schemaType instanceof RegExp) return assert(schemaType.test(value || ''), 'regex match on ' + schemaType.toString(), (value || 'nothing').toString()); return assert(value instanceof schemaType, 'instanceof ' + schemaType.toString()); }; \ No newline at end of file