diff --git a/lib/request.js b/lib/request.js index 16168b2fe8..067df4981b 100644 --- a/lib/request.js +++ b/lib/request.js @@ -473,8 +473,8 @@ AWS.Request = inherit({ if (retryError) this.failRequest(response); }); } else { - this.emitEvent('success', [response], this.handledErrorCallback); - this.emitEvent('complete', [response], this.handledErrorCallback); + this.emitEvent('success', [response], this.unhandledErrorCallback); + this.emitEvent('complete', [response], this.unhandledErrorCallback); } }); }, @@ -482,10 +482,10 @@ AWS.Request = inherit({ /** * @api private */ - failRequest: function failRequest(response) { - this.emitEvent('error', [response.error, response], this.handledErrorCallback); - this.emitEvent('complete', [response], this.handledErrorCallback); - }, + failRequest: function failRequest(response) { + this.emitEvent('error', [response.error, response], this.unhandledErrorCallback); + this.emitEvent('complete', [response], this.unhandledErrorCallback); + }, /** * @api private diff --git a/lib/sequential_executor.js b/lib/sequential_executor.js index 670717eaef..a3b0e7916d 100644 --- a/lib/sequential_executor.js +++ b/lib/sequential_executor.js @@ -258,18 +258,10 @@ AWS.SequentialExecutor = AWS.util.inherit({ err.domainThrown = false; this.domain.emit('error', err); } else { - throw err; + console.error(err.stack ? err.stack : err); + process.exit(1); } } - }, - - /** - * @api private - */ - handledErrorCallback: function handledErrorCallback(err) { - try { - this.unhandledErrorCallback(err); - } catch (e) { } } }); diff --git a/test/event_listeners.spec.coffee b/test/event_listeners.spec.coffee index 108169d450..ec48e39b3b 100644 --- a/test/event_listeners.spec.coffee +++ b/test/event_listeners.spec.coffee @@ -330,29 +330,40 @@ describe 'AWS.EventListeners', -> expect(completeHandler).toHaveBeenCalled() describe 'terminal callback error handling', -> + beforeEach -> + spyOn(process, 'exit') + spyOn(console, 'error') + + didError = -> + expect(console.error).toHaveBeenCalledWith('ERROR') + expect(process.exit).toHaveBeenCalledWith(1) + describe 'without domains', -> - it 'ignores exceptions raised from success event', -> + it 'logs exceptions raised from success event and exits process', -> helpers.mockHttpResponse 200, {}, [] request = makeRequest() request.on 'success', -> throw "ERROR" expect(-> request.send()).not.toThrow('ERROR') expect(completeHandler).toHaveBeenCalled() expect(retryHandler).not.toHaveBeenCalled() + didError() - it 'ignores exceptions raised from complete event', -> + it 'logs exceptions raised from complete event and exits process', -> helpers.mockHttpResponse 200, {}, [] request = makeRequest() request.on 'complete', -> throw "ERROR" expect(-> request.send()).not.toThrow('ERROR') expect(completeHandler).toHaveBeenCalled() expect(retryHandler).not.toHaveBeenCalled() + didError() - it 'ignores exceptions raised from error event', -> + it 'logs exceptions raised from error event and exits process', -> helpers.mockHttpResponse 500, {}, [] request = makeRequest() request.on 'error', -> throw "ERROR" expect(-> request.send()).not.toThrow('ERROR') expect(completeHandler).toHaveBeenCalled() + didError() describe 'with domains', -> it 'sends error raised from complete event to a domain', ->