Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Propagate errors from all callbacks up to main runloop

Fixes #74
  • Loading branch information...
commit e05a41ec00b4e947f8d3a41a6020c16949efd86b 1 parent 312e180
@lsegal lsegal authored
View
7 lib/request.js
@@ -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) {
@@ -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];
View
23 lib/sequential_executor.js
@@ -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;
},
/**
@@ -234,8 +231,16 @@ AWS.SequentialExecutor = AWS.util.inherit({
}
);
return this;
- }
+ },
+ /**
+ * @api private
+ */
+ unhandledErrorCallback: function unhandledErrorCallback(err) {
+ if (err) {
+ throw err;
+ }
+ }
});
/**
View
5 test/event_listeners.spec.coffee
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.