From 9cb31a5ee4d24fbbb29e7d78061ce4d47350150a Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 18 Sep 2020 13:06:58 -0500 Subject: [PATCH] fix(hydrate): improve dev server console error --- src/hydrate/runner/runtime-log.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/hydrate/runner/runtime-log.ts b/src/hydrate/runner/runtime-log.ts index 9372916b097..ccb0b14af0f 100644 --- a/src/hydrate/runner/runtime-log.ts +++ b/src/hydrate/runner/runtime-log.ts @@ -1,14 +1,36 @@ import type * as d from '../../declarations'; import { renderCatchError, renderBuildDiagnostic } from './render-utils'; -export function runtimeLogging(win: Window & typeof globalThis, opts: d.HydrateDocumentOptions, results: d.HydrateResults) { +export function runtimeLogging( + win: Window & typeof globalThis, + opts: d.HydrateDocumentOptions, + results: d.HydrateResults, +) { try { const pathname = win.location.pathname; win.console.error = (...msgs: any[]) => { - renderCatchError(results, [...msgs].join(', ')); - if (opts.runtimeLogging) { - runtimeLog(pathname, 'error', msgs); + const errMsg = msgs + .reduce((errMsg, m) => { + if (m) { + if (m.stack != null) { + return errMsg + ' ' + String(m.stack); + } else { + if (m.message != null) { + return errMsg + ' ' + String(m.message); + } + } + } + return String(m); + }, '') + .trim(); + + if (errMsg !== '') { + renderCatchError(results, errMsg); + + if (opts.runtimeLogging) { + runtimeLog(pathname, 'error', [errMsg]); + } } };