Skip to content

Commit 19eac71

Browse files
committed
Backport PR #1941: Catch and log handler exceptions in events.trigger
rather than throwing handler errors in the call to `.trigger()`, which I think we don't expect to happen (at least our code suggest we don't). Extensions can register buggy event handlers. These should not be able to cause failures in the event-triggering code paths. This should fix several avenues by which extensions (or other bugs) could prevent a notebook from loading. This closes #1602 in that the bug doesn't prevent notebook loading, but it doesn't fix the original error _parente is seeing. I don't fully understand the cause there, because notebook loading doesn't start before the page has finished loading.
1 parent 0b4e999 commit 19eac71

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

notebook/static/base/js/events.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,16 @@ define(['base/js/namespace', 'jquery'], function(IPython, $) {
2020
IPython.Events = Events;
2121
IPython.events = events;
2222

23-
return $([events]);
23+
var events = $([events]);
24+
25+
// catch and log errors in triggered events
26+
events._original_trigger = events.trigger;
27+
events.trigger = function (name, data) {
28+
try {
29+
this._original_trigger.apply(this, arguments);
30+
} catch (e) {
31+
console.error("Exception in event handler for " + name, e, arguments);
32+
}
33+
}
34+
return events;
2435
});

0 commit comments

Comments
 (0)