Skip to content

Commit

Permalink
Propagate errors from all callbacks up to main runloop
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
lsegal committed Mar 25, 2013
1 parent 312e180 commit e05a41e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
7 changes: 3 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ AWS.Request = inherit({
},

/**
* @private
* @api private
*/
emitEvents: function emitEvents(eventNames, response, doneCallback) {
if (!doneCallback) doneCallback = function() {};
if (!doneCallback) doneCallback = this.unhandledErrorCallback;
if (response.error) {
doneCallback.call(this, response.error);
} else if (eventNames.length === 0) {
Expand All @@ -362,8 +362,7 @@ AWS.Request = inherit({
* @api private
*/
emitEvent: function emitEvent(eventName, args, doneCallback) {
if (!doneCallback) doneCallback = function() {};

if (!doneCallback) doneCallback = this.unhandledErrorCallback;
var response = null;
if (AWS.util.isType(args, Array)) {
response = args[args.length - 1];
Expand Down
23 changes: 14 additions & 9 deletions lib/sequential_executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ AWS.SequentialExecutor = AWS.util.inherit({
* @api private
*/
emit: function emit(eventName, eventArgs, doneCallback) {
if (!doneCallback) doneCallback = function() {};
if (!doneCallback) doneCallback = this.unhandledErrorCallback;

var listeners = this.listeners(eventName);
if (listeners.length === 0) {
doneCallback.call(this);
return false;
} else {
this.callListeners(listeners, eventArgs, doneCallback);
return true;
}
var count = listeners.length;
this.callListeners(listeners, eventArgs, doneCallback);
return count > 0;
},

/**
Expand Down Expand Up @@ -234,8 +231,16 @@ AWS.SequentialExecutor = AWS.util.inherit({
}
);
return this;
}
},

/**
* @api private
*/
unhandledErrorCallback: function unhandledErrorCallback(err) {
if (err) {
throw err;
}
}
});

/**
Expand Down
5 changes: 2 additions & 3 deletions test/event_listeners.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,5 @@ describe 'AWS.EventListeners', ->
request = makeRequest()
request.on 'error', ->
throw "ERROR"
response = request.send()
expect(completeHandler).toHaveBeenCalled()
expect(response.error).toBe("ERROR")
expect(-> request.send()).toThrow('ERROR')
expect(completeHandler).not.toHaveBeenCalled()

0 comments on commit e05a41e

Please sign in to comment.