fix(ses): Trap and report errors
Ensures that any error that bottoms out the stack of an event in Node.js or on the web gets reported through the tamed console so its stack can be revealed.
Fixes
MODIFY
packages/ses/src/error/tame-console.js
packages/ses/src/error/tame-console.js
// @ts-check
+/* global process, window */
import { loggedErrorHandler as defaultHandler } from './assert.js';
import { makeCausalConsole } from './console.js';
@@ -37,5 +38,34 @@ export const tameConsole = (
};
}
const causalConsole = makeCausalConsole(originalConsole, loggedErrorHandler);
+
+ // Attach platform-specific error traps such that any error that bottoms out
+ // an event will get unwrapped by the causal console, revealing the error
+ // stack to the console for debugging.
+
+ // Node.js
+ if (
+ typeof process === 'object' &&
+ process !== null &&
+ typeof process.on === 'function' &&
+ typeof process.exit === 'function'
+ ) {
+ process.on('uncaughtException', error => {
+ causalConsole.error(error);
+ process.exit(process.exitCode || -1);
+ });
+ }
+
+ // Web
+ if (
+ typeof window === 'object' &&
+ window !== null &&
+ typeof window.addEventListener === 'function'
+ ) {
+ window.addEventListener('error', event => {
+ causalConsole.error(event.error);
+ });
+ }
+
return { console: causalConsole };
};

fix(ses): Trap and report errors

Ensures that any error that bottoms out the stack of an event in Node.js or on the web gets reported through the tamed console so its stack can be revealed.

Fixes #769