Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add an error handler for all event callbacks #542

Closed
wants to merge 1 commit into from

2 participants

@ConradIrwin

Javascript has a default error handler window.onerror though there are several issues with this, the most poignant being that you can't get at the error object itself, nor the associated stack trace.

Due to the large amount of code that ends up being run as a direct consequence of user-interaction on a webpage, allowing developers to catch all errors that are raised within event handlers added by zepto allows significantly improved debugging ability (particularly when coupled to a service like Airbrake or Bugsnag).

Obviously this is no substitute for handling errors locally; but it does significantly help with tracking down hard to find problems and unexpected exceptions.

This patch was inspired by a similar change made to ember.js emberjs/ember.js@99125d9...539f5a1#L0R40 (MIT license).

@madrobby
Owner

I don't think this is an issue, exceptions are thrown and should pop up in the debugger of your browser, no? I'm unsure about the specific use case here. Feel free to reopen with specific examples.

@madrobby madrobby closed this
@ConradIrwin

At work we used an exception tracker (there are a few, https://bugsnag.com/, https://airbrake.io, etc.) so that exceptions that happen in production can still be tracked.

Without a change like this, it's basically impossible to get enough information from a crash for an exception report to be useful. The installer you get if you visit https://intro.linkedin.com/ on an iPhone is using this patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 6, 2012
  1. @ConradIrwin
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/event.js
View
9 src/event.js
@@ -41,7 +41,14 @@
var delegate = getDelegate && getDelegate(fn, event),
callback = delegate || fn
var proxyfn = function (event) {
- var result = callback.apply(element, [event].concat(event.data))
+ var result
+ if ($.onerror) {
+ try {
+ result = callback.apply(element, [event].concat(event.data))
+ } catch(e) { $.onerror(e) }
+ } else {
+ result = callback.apply(element, [event].concat(event.data))
+ }
if (result === false) event.preventDefault()
return result
}
Something went wrong with that request. Please try again.