YUKI Hiroshi
null+****@clear*****
Mon Oct 15 16:42:09 JST 2012
YUKI Hiroshi 2012-10-15 16:42:09 +0900 (Mon, 15 Oct 2012) New Revision: 5e93634da47be7205dafcb38331313c8308a19ff https://github.com/groonga/gcs/commit/5e93634da47be7205dafcb38331313c8308a19ff Log: Handle errors more strictly Modified files: bin/gcs-delete-domain bin/gcs-describe-domain lib/command-line.js Modified: bin/gcs-delete-domain (+4 -7) =================================================================== --- bin/gcs-delete-domain 2012-10-15 16:35:09 +0900 (99d58bf) +++ bin/gcs-delete-domain 2012-10-15 16:42:09 +0900 (f9ac69c) @@ -18,13 +18,10 @@ commandLine.assertDomainExistsHTTP(function() { commandLine.cloudSearch.DeleteDomain( { DomainName: commandLine.domainName }, function(error, response) { - if (error) { - console.log('Unexpected error: ' + JSON.stringify(error)); - process.exit(1); - } else { - console.log(successMessage); - process.exit(0); - } + if (error) + commandLine.raiseFatalError(error); + console.log(successMessage); + process.exit(0); } }); } Modified: bin/gcs-describe-domain (+8 -0) =================================================================== --- bin/gcs-describe-domain 2012-10-15 16:35:09 +0900 (e2be20b) +++ bin/gcs-describe-domain 2012-10-15 16:42:09 +0900 (98c0e9a) @@ -53,18 +53,26 @@ function reportStatus(domain, indexFields) { var domainName = commandLine.domainName; if (domainName) { commandLine.getDomainStatus(domainName, function(error, domain) { + if (error) + commandLine.raiseFatalError(error); commandLine.getIndexFieldStatuses(domainName, function(error, indexFields) { + if (error) + commandLine.raiseFatalError(error); reportStatus(domain, indexFields); process.exit(0); }); }); } else { commandLine.getDomainStatuses(function(error, domains) { + if (error) + commandLine.raiseFatalError(error); var indexFieldStatuses = {}; var preparedStatusesCount = 0; domains.forEach(function(domain) { var domainName = domain.DomainName; commandLine.getIndexFieldStatuses(domainName, function(error, indexFields) { + if (error) + commandLine.raiseFatalError(error); indexFieldStatuses[domainName] = indexFields; preparedStatusesCount++; if (preparedStatusesCount == domains.length) { Modified: lib/command-line.js (+19 -18) =================================================================== --- lib/command-line.js 2012-10-15 16:35:09 +0900 (3d40a55) +++ lib/command-line.js 2012-10-15 16:42:09 +0900 (d18fd63) @@ -121,34 +121,38 @@ CommandLineInterface.prototype = { return this.program.confirm.apply(this.program, arguments); }, + raiseFatalError: function(error) { + if (typeof error != 'string') + error = 'Unexpected error: ' + JSON.strigify(error); + console.log(error); + process.exit(1); + }, + assertHaveDomainName: function() { - if (!this.domainName) { - console.log('You must specify the domain name.'); - process.exit(1); - } + if (!this.domainName) + this.raiseFatalError('You must specify the domain name.'); return this; }, getDomainStatus: function(domainName, callback) { + var self = this; this.getDomainStatuses( { 'DomainNames.member.1' : domainName }, function(error, domainStatuses) { if (domainStatuses.length) { callback(null, domainStatuses[0]); } else { - console.log('You must specify an existing domain name.'); - process.exit(1); + self.raiseFatalError('You must specify an existing domain name.'); } } ); }, getDomainStatuses: function(options, callback) { + var self = this; var domainStatusesCallback = function(error, response) { - if (error) { - console.log('Unexpected error: ' + JSON.stringify(error)); - process.exit(1); - } + if (error) + self.raiseFatalError(error); var domainStatuses = response.Body .DescribeDomainsResponse .DescribeDomainsResult @@ -163,13 +167,12 @@ CommandLineInterface.prototype = { }, getIndexFieldStatuses: function(domainName, callback) { + var self = this; this.cloudSearch.DescribeIndexFields( { DomainName: domainName }, function(error, response) { - if (error) { - console.log('Unexpected error: ' + JSON.stringify(error)); - process.exit(1); - } + if (error) + self.raiseFatalError(error); var indexFields = response.Body .DescribeIndexFieldsResponse @@ -209,10 +212,8 @@ CommandLineInterface.prototype = { }, assertDomainExists: function() { - if (!this.domain.exists()) { - console.log('You must specify an existing domain name.'); - process.exit(1); - } + if (!this.domain.exists()) + this.raiseFatalError('You must specify an existing domain name.'); return this; }, -------------- next part -------------- HTML����������������������������...Download