From d85a67cf37f93dcbcaf7fcc43fe2348af2d3529b Mon Sep 17 00:00:00 2001 From: exoego Date: Thu, 17 Jan 2019 21:20:28 +0900 Subject: [PATCH 1/3] Add detail and recovery operation. --- lib/plugins/aws/deploy/lib/checkForChanges.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.js b/lib/plugins/aws/deploy/lib/checkForChanges.js index fcb72af4a..470b2ae33 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.js @@ -41,7 +41,17 @@ module.exports = { return this.provider.request('S3', 'listObjectsV2', params - ).then((result) => { + ).catch((reason) => { + if (!_.includes(reason.message, 'The specified bucket does not exist')) { + return BbPromise.reject(reason); + } + const stackName = this.provider.naming.getStackName(); + return BbPromise.reject(new this.serverless.classes.Error([ + `The serverless deployment bucket "${params.Bucket}" does not exist.`, + `Create it manually if you want to reuse the CloudFormation stack "${stackName}",`, + 'or delete the stack then run "sls deploy".', + ].join(' '))); + }).then((result) => { if (result && result.Contents && result.Contents.length) { const objects = result.Contents; From d4cb2b6684f09dc67ea1de43edbb3adad8a394f6 Mon Sep 17 00:00:00 2001 From: exoego Date: Fri, 18 Jan 2019 06:19:43 +0900 Subject: [PATCH 2/3] Add tests. --- .../aws/deploy/lib/checkForChanges.test.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.test.js b/lib/plugins/aws/deploy/lib/checkForChanges.test.js index 5345f397b..d5542c18d 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.test.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.test.js @@ -135,6 +135,23 @@ describe('checkForChanges', () => { }); }); + it('should translate error if rejected due to missing bucket', () => { + listObjectsV2Stub + .rejects(new serverless.classes.Error('The specified bucket does not exist')); + + return expect(awsDeploy.getMostRecentObjects()).to.be.rejectedWith([ + `The serverless deployment bucket "${awsDeploy.bucketName}" does not exist.`, + 'Create it manually if you want to reuse the CloudFormation stack "my-service-dev",', + 'or delete the stack then run "sls deploy".', + ].join(' ')); + }); + + it('should throw original error if rejected not due to missing bucket', () => { + listObjectsV2Stub + .rejects(new serverless.classes.Error('Other reason')); + return expect(awsDeploy.getMostRecentObjects()).to.be.rejectedWith('Other reason'); + }); + it('should resolve if result array is empty', () => { const serviceObjects = { Contents: [], From e334bcd40a2b59abccbde93ef6a87e60d4230aed Mon Sep 17 00:00:00 2001 From: exoego Date: Fri, 18 Jan 2019 06:26:30 +0900 Subject: [PATCH 3/3] Update message to include a case of complete deletion. --- lib/plugins/aws/deploy/lib/checkForChanges.js | 2 +- lib/plugins/aws/deploy/lib/checkForChanges.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.js b/lib/plugins/aws/deploy/lib/checkForChanges.js index 470b2ae33..bbc7bc0e5 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.js @@ -49,7 +49,7 @@ module.exports = { return BbPromise.reject(new this.serverless.classes.Error([ `The serverless deployment bucket "${params.Bucket}" does not exist.`, `Create it manually if you want to reuse the CloudFormation stack "${stackName}",`, - 'or delete the stack then run "sls deploy".', + 'or delete the stack if it is no longer required.', ].join(' '))); }).then((result) => { if (result && result.Contents && result.Contents.length) { diff --git a/lib/plugins/aws/deploy/lib/checkForChanges.test.js b/lib/plugins/aws/deploy/lib/checkForChanges.test.js index d5542c18d..4a8e9fb4f 100644 --- a/lib/plugins/aws/deploy/lib/checkForChanges.test.js +++ b/lib/plugins/aws/deploy/lib/checkForChanges.test.js @@ -142,7 +142,7 @@ describe('checkForChanges', () => { return expect(awsDeploy.getMostRecentObjects()).to.be.rejectedWith([ `The serverless deployment bucket "${awsDeploy.bucketName}" does not exist.`, 'Create it manually if you want to reuse the CloudFormation stack "my-service-dev",', - 'or delete the stack then run "sls deploy".', + 'or delete the stack if it is no longer required.', ].join(' ')); });