Skip to content

Commit 7433f41

Browse files
committed
eliminate most ways slate would visibly crash for a user, maybe
1 parent def7ba6 commit 7433f41

File tree

1 file changed

+14
-3
lines changed
  • src/packages/frontend/editors/slate/keyboard

1 file changed

+14
-3
lines changed

src/packages/frontend/editors/slate/keyboard/register.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,22 @@ const keyHandlers: { [x: string]: KeyHandler } = {};
3939

4040
export function register(
4141
key: Partial<Key> | Partial<Key>[],
42-
handler: KeyHandler
42+
handler: KeyHandler,
4343
): void {
44+
const handlerNoThrow = (opts) => {
45+
try {
46+
return handler(opts);
47+
} catch (err) {
48+
// making this a warning -- there's a number of situations where the
49+
// it's best to just not do anything special, rather than crash cocalc.
50+
console.log("slate key handler throw ", key, err);
51+
return false;
52+
}
53+
};
54+
4455
if (key[0] != null) {
4556
for (const k of key as Partial<Key>[]) {
46-
register(k, handler);
57+
register(k, handlerNoThrow);
4758
}
4859
return;
4960
}
@@ -53,7 +64,7 @@ export function register(
5364
// making this a warning to support hot module reloading.
5465
console.warn(`WARNING: there is already a handler registered for ${s}`);
5566
}
56-
keyHandlers[s] = handler;
67+
keyHandlers[s] = handlerNoThrow;
5768
}
5869

5970
export function getHandler(event): KeyHandler | undefined {

0 commit comments

Comments
 (0)