Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Only install global error handler if we have at least one subscriber #37

Closed
wants to merge 1 commit into from

Conversation

pieter
Copy link

@pieter pieter commented Feb 26, 2013

This changes TraceKit to only install a window.onerror handler if we get a subscriber.

Even though the onerror handler is always necessary when catching exceptions for IE, there's no need for the handler if there are no exception handlers, since the exception would be ignored anyway.

Catching exceptions in development mode can be very annoying and can mess up debugging by changing backtraces to point to the last point where an exception has been rethrown, for example. For this reason, it's often easiest to not have any global exception handlers while debugging.

The way TraceKit was set up, this basically meant you were forced not to load in TraceKit code during debugging. This also then means that you'll get a lot of extra code in your production builds that you haven't tested in development.

With this change, TraceKit can still be loaded in development builds. If no subscriber is registered for handling exceptions, no global error handler will be installed, so debug builds can continue to work as normal.

Refers to #21 and #14.


function installGlobalHandler ()
{
if (window.onerror === traceKitWindowOnError) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an internal flag would be better here.

With multiple libraries attaching to window.onerror, this can end up badly.
Do you mind adding a flag? Like- _isOnerrorHandlerInstalled?

@pieter
Copy link
Author

pieter commented Mar 3, 2013

Sure, I'll do so tomorrow.

@occ
Copy link
Owner

occ commented Mar 3, 2013

Actually- I just patched it.
How does 351669d look?

@pieter
Copy link
Author

pieter commented Mar 3, 2013

Seems good, thanks. I'll close this then.

@pieter pieter closed this Mar 3, 2013
@occ
Copy link
Owner

occ commented Mar 3, 2013

Merged to master. Thanks for the patch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants