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

Mark Wubben mark at novemberborn.net
Wed Jun 6 18:49:45 EDT 2012


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



More information about the dojo-contributors mailing list