diff --git a/bin/serverless b/bin/serverless index 7dab37352..e70da50d7 100755 --- a/bin/serverless +++ b/bin/serverless @@ -17,4 +17,7 @@ process.noDeprecation = true; }); return serverless.init().then(() => serverless.run()); -}).catch(e => logError(e)))(); +}).catch(e => { + process.exitCode = 1; + logError(e); +}))(); diff --git a/lib/plugins/aws/invoke/index.js b/lib/plugins/aws/invoke/index.js index 9533b639c..7c5a79fe9 100644 --- a/lib/plugins/aws/invoke/index.js +++ b/lib/plugins/aws/invoke/index.js @@ -120,7 +120,7 @@ class AwsInvoke { } if (invocationReply.FunctionError) { - process.exit(1); + return BbPromise.reject(new Error("Invoked function errored")); } return BbPromise.resolve(); diff --git a/lib/plugins/aws/invoke/index.test.js b/lib/plugins/aws/invoke/index.test.js index 12fd35f91..622259775 100644 --- a/lib/plugins/aws/invoke/index.test.js +++ b/lib/plugins/aws/invoke/index.test.js @@ -260,8 +260,7 @@ describe('AwsInvoke', () => { return awsInvoke.log(invocationReplyMock); }); - it('should exit on error', () => { - const exit = sinon.stub(process, 'exit'); + it('rejects the promise for failed invocations', (done) => { const invocationReplyMock = { Payload: ` { @@ -272,8 +271,11 @@ describe('AwsInvoke', () => { FunctionError: true, }; - awsInvoke.log(invocationReplyMock); - expect(exit.calledWithExactly(1)).to.be.equal(true); + awsInvoke.log(invocationReplyMock).then(p => { + done(new Error("Promise resolved")); + }, (e) => { + done() + }); }); }); });