-
Notifications
You must be signed in to change notification settings - Fork 0
Thoughts on Error Handling
Note: I am simplifying by considering only callback functions in the topics, but direct returns, promises, and objects also apply.
###Preface
This proposal is to make vows error handling easier to understand. It is completely backwards-compatible with vows 0.7.0. I also have some documentation here.
###Question
Error-handling is a source of frustration for vows users. Can context options set in the topic make this easier?
###Use Cases
This is how I rank use cases in order of importance
- Node-Style callbacks (error, data); Vows reports errors.
- Single parameter callbacks (data); Vows reports errors.
- Node-Style callbacks (error, data); Errors are sent to the vow, not reported.
- Multiple-parameter callbacks with only data parameters; Vows reports errors.
- Single parameter callbacks (data); Errors are sent to the vow, not reported.
- Multiple-parameter callbacks with an error parameter (error, data1, data2, etc.); Vows reports errors.
- Multiple-parameter callbacks; Errors are sent to the vow, not reported.
Node-Style callbacks (error, data); Vows reports errors
- Current: Have the vow accept one parameter (the data).
- Better: None.
Single parameter callbacks (data); Vows reports errors
- Current: Wrap the callback, providing an extra null parameter at the front
- Better:
Set this option in the topic:
this.callback.errors = false
Node-Style callbacks (error, data); Errors are sent to the vow, not reported
- Current: Set
options.error
tofalse
in the suite. - Current: Add a second parameter to the vow.
- Better: None.
Multiple-parameter callbacks with only data parameters; Vows reports errors
- Current: Wrap the callback, combining all the data parameters. Separate the parameters again after they're received by the vow.
- Better:
Set this option in the topic:
this.callback.multi = true
Single parameter callbacks (data); Errors are sent to the vow, not reported
- Current: Add a second unused parameter to the vow, then check the first parameter to see if it is an error or data.
- Better:
Use a combination of
this.callback.errors = false
and a vow with two parameters (error, data).
Multiple-parameter callbacks with an error parameter (error, data1, data2, etc.); Vows reports errors
- Current: Wrap the callback, combining all the data parameters. Separate the parameters again after they're received by the vow.
- Better:
Set these options:
this.callback.multi = true
this.callback.errors = true
Multiple-parameter callbacks; Errors are sent to the vow, not reported
- Current: Add an error parameter at the front of the vows parameters
- Better: None. (Worse, actually--see Notes)
- Notes: If case 4 is implemented as above then for case 7 to continue to work as before, the user must not set
this.callback.multi
totrue
. The possibility of this option being set by accident is a drawback. The user must remember only to setthis.callback.multi
totrue
when vows should report errors.
The above proposal provides equal or better support for six of the seven use cases for error-reporting. It provides slightly worse support only for the least-important case.