Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: fail-safe error formatting in fault-isolating emit (#8931)
[._.]/ Adam Eivyecc6f31f980b
diff --git a/server/lib/faultIsolatedEmitter.js b/server/lib/faultIsolatedEmitter.jsindex 01af3bba64..bb16d58399 100644--- a/server/lib/faultIsolatedEmitter.js+++ b/server/lib/faultIsolatedEmitter.js@@ -27,8 +27,15 @@ export function makeEmitterFaultIsolating(emitter) {try {listener.apply(emitter, args);} catch (err) {- const message = err instanceof Error ? err.message : String(err);- console.error(`❌ Listener for '${String(eventName)}' threw: ${message}`);+ // Formatting itself must not throw (a hostile `.message` getter, a+ // Symbol, a value whose `String()` throws) — that would defeat the+ // isolation this loop exists to provide.+ try {+ const message = err instanceof Error ? err.message : String(err);+ console.error(`❌ Listener for '${String(eventName)}' threw: ${message}`);+ } catch {+ console.error(`❌ Listener for '${String(eventName)}' threw (unformattable error)`);+ }}}return listeners.length > 0;diff --git a/server/lib/faultIsolatedEmitter.test.js b/server/lib/faultIsolatedEmitter.test.jsindex a08b799942..0363827d40 100644--- a/server/lib/faultIsolatedEmitter.test.js+++ b/server/lib/faultIsolatedEmitter.test.js@@ -52,6 +52,27 @@ describe('makeEmitterFaultIsolating', () => {expect(secondListener).toHaveBeenCalled();});+ it('does not itself throw when formatting a thrown error explodes (hostile message getter)', () => {+ const emitter = makeEmitterFaultIsolating(new EventEmitter());+ const secondListener = vi.fn();+ const hostile = Object.create(Error.prototype);+ Object.defineProperty(hostile, 'message', {+ get() {+ throw new Error('cannot read message');+ },+ });+ emitter.on('completed', () => {+ throw hostile;+ });+ emitter.on('completed', secondListener);++ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});+ expect(() => emitter.emit('completed')).not.toThrow();+ errorSpy.mockRestore();++ expect(secondListener).toHaveBeenCalled();+ });+it('returns true when listeners existed, false otherwise', () => {const emitter = makeEmitterFaultIsolating(new EventEmitter());expect(emitter.emit('unheard')).toBe(false);