Opened 12 years ago

Closed 12 years ago

#4337 closed defect (fixed)

[patch][cla]Unable to return a custom error from a Deferred Canceller.

Reported by: jonu Owned by: alex
Priority: high Milestone: 1.0
Component: General Version: 0.9
Keywords: deferred cancel xhr Cc:
Blocked By: Blocking:

Description

The deferred documentation says that if the "canceller" returns a custom error, that custom error will be sent to the errback chain. That is essential behavior for generic cancellers.

Right now the cancel call is hacked to always return a new Exception, and the err.dojoType = "cancel" is glued to that exception and passed to the errback chain.

The cancel call should pass the return value from the canceller, or a new Exception if the canceller doesn't return anything, to the errback chain. Deferred that depend on particular values in the Exception should implement a custom canceller to correctly configure their cancel error.

Attachments (2)

Deferred_cancel.patch (802 bytes) - added by guest 12 years ago.
A patch that causes the Deferred object to return the result of the cancel call, if the result is an Error.
xhr_cancel.patch (412 bytes) - added by guest 12 years ago.
A patch that causes xhr to return an Error in the format it expects from the cancel function. This can be applied in addition to the Deferred.js patch, but the Deferred.js patch does not break xhr.js as is.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 12 years ago by guest

I believe the hack is in place to support the xhr object.

Changed 12 years ago by guest

Attachment: Deferred_cancel.patch added

A patch that causes the Deferred object to return the result of the cancel call, if the result is an Error.

Changed 12 years ago by guest

Attachment: xhr_cancel.patch added

A patch that causes xhr to return an Error in the format it expects from the cancel function. This can be applied in addition to the Deferred.js patch, but the Deferred.js patch does not break xhr.js as is.

comment:2 Changed 12 years ago by guest

The first patch can be applied safely. It does not change the cancel behavior unless the cancel function returns an object of type Error. So, it does not disturb the existing xhr cancel hack.

The second patch can be applied to make xhr stop depending on custom deferred cancel behavior.

A third patch could be applied in the future to make Deferred cancel pass something else by default after these two patches are applied.

comment:3 Changed 12 years ago by guest

Ah, and three xhr tests are broken both before and after applying these patches. The cancel subtest works both before and after.

comment:4 Changed 12 years ago by James Burke

We need you to file a CLA and identify yourself in order for us to take patches. Please add your contact info to the bug in order for us to consider it, and send in a CLA (http://dojotoolkit.org/cla) if you have not already.

comment:5 Changed 12 years ago by jonu

These patches are mine. I just got my user account for trac. My CLA is on file.

comment:6 Changed 12 years ago by jonu

Reporter: changed from guest to jonu

comment:7 Changed 12 years ago by jonu

Keywords: deferred cancel xhr added

comment:8 Changed 12 years ago by James Burke

Milestone: 1.0
Summary: Unable to return a custom error from a Deferred Canceller.[patch][cla]Unable to return a custom error from a Deferred Canceller.

comment:9 Changed 12 years ago by James Burke

Owner: changed from anonymous to alex

Assigning to Alex, since I'm not totally comfortable yet on all the permutations of Deferred usage.

comment:10 Changed 12 years ago by alex

Resolution: fixed
Status: newclosed

(In [10975]) merging patch from jonu to allow custom errors in Deferreds. Very useful. Fixes #4337

Note: See TracTickets for help on using tickets.