[dojo-contributors] Instrumenting deferreds to log (unhandled) rejection values

Mike Wilcox mike at mikewilcox.net
Wed Jun 6 19:27:13 EDT 2012


It's awesome that you are moving forward on this.

I am concerned that you would have to go through a lot of effort and have a lot of knowledge to get Deferreds to throw uncaught errors - it would still catch unaware devs off guard.

I've been playing with this today, and I inserted this line in Deferred.then:

errback = errback || function(e){ console.error('uncaught error in deferred:', e); }

This works well, except that it throws multiple times in a chain, so it's not perfect.
 
Mike Wilcox
http://clubajax.org
mike at mikewilcox.net



On Jun 6, 2012, at 5:49 PM, Mark Wubben wrote:

> 1.7 supported `config.deferredOnError` which would be called with the error value for every rejected deferred. If not configured `console.error()` would be used instead. I removed this from `dojo/_base/Deferred` with the new promise API in 1.8.
> 
> This means there is no clear way of noticing errors, other than your code not working as expected. LiuCougar pointed out he was actually using `config.deferredOnError` to report errors to the server.
> 
> The naive implementation in 1.7 logs all rejection values, assuming they are actually code errors. That's not necessarily true, I often intentionally throw errors in my own code to communicate a failure state. I tried to find a middle ground with `instrumentRejected`, see <https://github.com/novemberborn/dojo/commit/0fffe22cf97504c90e45cd521cf2c4b504e65e5d>.
> 
> Depending on a has() test (for the `deferredEnableInstrumentation` config flag), `Deferred.instrumentRejected()` is called (if specified) with the error value and whether a listener was registered for it. `dojo/promise/instrumenting` can set up default reporters. Either to immediately log the error (1.7 behavior) or to detect unhandled errors after a short interval. These are useful during development, you'd want to roll your own to log unhandled errors in production. See <https://gist.github.com/14c8266d22444dc6f030>.
> 
> Question 1: Is this a useful approach?
> 
> Question 2: How do we get this enabled by default during development?
> 
> Cheers,
> 
> --
> Mark Wubben
> 
> http://novemberborn.net
> http://twitter.com/novemberborn
> 
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-contributors



More information about the dojo-contributors mailing list