/** * Length cap for extracted messages. Aligned with the core scrubber's * MAX_STRING_LENGTH so an error-reporting site never retains (dedup keys) or * forwards more than the telemetry layer would keep anyway. */ const MAX_SAFE_ERROR_MESSAGE_LENGTH = 500 /** * Extract a bounded message from any thrown value without ever throwing. * Error-reporting sites run inside catch blocks and third-party emitters, * where a poisoned `message` getter or a throwing `toString()` would replace * the real failure with its own — and an unbounded message retained as a * dedup key is a memory footgun. (`uwc-bridge-child` keeps a local copy — * that package stays dependency-free; keep the two in sync.) */ export function safeErrorMessage(error: unknown): string { try { const message = error instanceof Error ? error.message : String(error) return message.length > MAX_SAFE_ERROR_MESSAGE_LENGTH ? message.slice(0, MAX_SAFE_ERROR_MESSAGE_LENGTH) : message } catch { return 'Unreadable error object' } }