Skip to content

Commit aac5bd2

Browse files
authored
fix: Catch errors when emitting events to prevent breaking entire layout (#1353)
- Added a try/catch around all events that are emitted from Golden Layout - Added @deephaven/log to golden layout so we can log the error - Tested using the steps in https://github.com/deephaven/deephaven-js-plugins/issues/26 - Fixes #1352
1 parent 5e0db54 commit aac5bd2

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

packages/golden-layout/src/utils/EventEmitter.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ class EventEmitter {
6565
if (subs) {
6666
for (let i = 0; i < subs.length; i++) {
6767
const ctx = subs[i].ctx || {};
68-
subs[i].fn.apply(ctx, args);
68+
try {
69+
subs[i].fn.apply(ctx, args);
70+
} catch (e) {
71+
console.error('Error while emitting event:', e);
72+
}
6973
}
7074
}
7175

@@ -75,7 +79,11 @@ class EventEmitter {
7579

7680
for (let i = 0; i < allEventSubs.length; i++) {
7781
const ctx = allEventSubs[i].ctx || {};
78-
allEventSubs[i].fn.apply(ctx, args);
82+
try {
83+
allEventSubs[i].fn.apply(ctx, args);
84+
} catch (e) {
85+
console.error('Error while emitting event to allEventSubs:', e);
86+
}
7987
}
8088
}
8189

packages/golden-layout/tsconfig.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
"rootDir": "src/",
55
"outDir": "dist/"
66
},
7-
"include": [
8-
"src/**/*.ts",
9-
"src/**/*.tsx",
10-
"src/**/*.js",
11-
"src/**/*.jsx"
12-
],
13-
"exclude": [
14-
"node_modules"
15-
]
16-
}
7+
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"],
8+
"exclude": ["node_modules"]
9+
}

0 commit comments

Comments
 (0)