Skip to content

Commit

Permalink
fix: Catch errors when emitting events to prevent breaking entire layout
Browse files Browse the repository at this point in the history
- 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 deephaven#1352
  • Loading branch information
mofojed committed Jun 8, 2023
1 parent 5e0db54 commit 9acb901
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/golden-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type": "module",
"dependencies": {
"@deephaven/components": "file:../components",
"@deephaven/log": "file:../log",
"jquery": "^3.6.0"
},
"peerDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions packages/golden-layout/src/utils/EventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import Log from '@deephaven/log';

const log = Log.module('EventEmitter');

/**
* A generic and very fast EventEmitter
* implementation. On top of emitting the
Expand Down Expand Up @@ -65,7 +69,11 @@ class EventEmitter {
if (subs) {
for (let i = 0; i < subs.length; i++) {
const ctx = subs[i].ctx || {};
subs[i].fn.apply(ctx, args);
try {
subs[i].fn.apply(ctx, args);
} catch (e) {
log.error('Error while emitting event:', e);
}
}
}

Expand All @@ -75,7 +83,11 @@ class EventEmitter {

for (let i = 0; i < allEventSubs.length; i++) {
const ctx = allEventSubs[i].ctx || {};
allEventSubs[i].fn.apply(ctx, args);
try {
allEventSubs[i].fn.apply(ctx, args);
} catch (e) {
log.error('Error while emitting event to allEventSubs:', e);
}
}
}

Expand Down
14 changes: 4 additions & 10 deletions packages/golden-layout/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
"rootDir": "src/",
"outDir": "dist/"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.js",
"src/**/*.jsx"
],
"exclude": [
"node_modules"
]
}
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"],
"exclude": ["node_modules"],
"references": [{ "path": "../components" }, { "path": "../log" }]
}

0 comments on commit 9acb901

Please sign in to comment.