YUKI Hiroshi
null+****@clear*****
Mon Nov 5 15:07:05 JST 2012
YUKI Hiroshi 2012-11-05 15:07:05 +0900 (Mon, 05 Nov 2012) New Revision: bdcde0d44e130bcefb1d950e819f9ed8ec51f77b https://github.com/groonga/gcs/commit/bdcde0d44e130bcefb1d950e819f9ed8ec51f77b Log: Update error message for invalid domain name Modified files: lib/database/domain.js test/database-domain.test.js Modified: lib/database/domain.js (+6 -3) =================================================================== --- lib/database/domain.js 2012-11-05 15:01:24 +0900 (3fa8e7e) +++ lib/database/domain.js 2012-11-05 15:07:05 +0900 (7e9fa9e) @@ -72,9 +72,12 @@ function assertValidDomainName(domain) { errors.push(commonPrefix + 'Member must have length smaller ' + 'than or equal to ' + exports.MAXIMUM_NAME_LENGTH); - if (errors.length) - throw new Error(errors.length + ' validation errors detected: ' + - errors.join('; ')); + if (errors.length) { + var prefix = errors.length > 1 ? + errors.length + ' validation errors detected: ' : + '1 validation error detected: '; + throw new Error(prefix + errors.join('; ')); + } } Modified: test/database-domain.test.js (+6 -4) =================================================================== --- test/database-domain.test.js 2012-11-05 15:01:24 +0900 (95ccd76) +++ test/database-domain.test.js 2012-11-05 15:07:05 +0900 (fe4d1cf) @@ -58,7 +58,7 @@ suite('database', function() { test('too short (2 characters)', function() { assert.throw(function() { var domain = new Domain('va'); - }, '1 validation errors detected: ' + + }, '1 validation error detected: ' + 'Value \'va\' at \'domainName\' failed to satisfy constraint: ' + 'Member must have length greater than or equal to 3'); }); @@ -72,8 +72,10 @@ suite('database', function() { test('hyphen', function() { assert.throw(function() { + try { var domain = new Domain('domain-name'); - }, '1 validation errors detected: ' + + } catch(e) { console.log(e); } + }, '1 validation error detected: ' + 'Value \'domain_name\' at \'domainName\' failed to satisfy constraint: ' + 'Member cannot include these characters: \'-\''); }); @@ -81,7 +83,7 @@ suite('database', function() { test('underscore', function() { assert.throw(function() { var domain = new Domain('domain_name'); - }, '1 validation errors detected: ' + + }, '1 validation error detected: ' + 'Value \'domain_name\' at \'domainName\' failed to satisfy constraint: ' + 'Member must satisfy regular expression pattern: [a-z][a-z0-9\\-]+'); }); @@ -89,7 +91,7 @@ suite('database', function() { test('upper case', function() { assert.throw(function() { var domain = new Domain('DomainName'); - }, '1 validation errors detected: ' + + }, '1 validation error detected: ' + 'Value \'DomainName\' at \'domainName\' failed to satisfy constraint: ' + 'Member must satisfy regular expression pattern: [a-z][a-z0-9\\-]+'); }); -------------- next part -------------- HTML����������������������������...ダウンロード