diff --git a/src/client/client-log.ts b/src/client/client-log.ts index 7114105cf2a..5dcd1a8874c 100644 --- a/src/client/client-log.ts +++ b/src/client/client-log.ts @@ -1,7 +1,8 @@ import type * as d from '../declarations'; import { BUILD } from '@app-data'; -export let consoleError: d.ErrorHandler = (e: any, _?: any) => console.error(e); +let customError: d.ErrorHandler ; +export const consoleError: d.ErrorHandler = (e: any, el?: any) => (customError || console.error)(e, el); export const STENCIL_DEV_MODE = BUILD.isTesting ? ['STENCIL:'] // E2E testing @@ -13,4 +14,4 @@ export const consoleDevWarn = (...m: any[]) => console.warn(...STENCIL_DEV_MODE, export const consoleDevInfo = (...m: any[]) => console.info(...STENCIL_DEV_MODE, ...m); -export const setErrorHandler = (handler: d.ErrorHandler) => consoleError = handler; +export const setErrorHandler = (handler: d.ErrorHandler) => customError = handler; diff --git a/src/compiler/bundle/worker-plugin.ts b/src/compiler/bundle/worker-plugin.ts index 911f594462b..a33bcc3ef31 100644 --- a/src/compiler/bundle/worker-plugin.ts +++ b/src/compiler/bundle/worker-plugin.ts @@ -3,6 +3,7 @@ import type { Plugin, TransformResult, PluginContext } from 'rollup'; import { bundleOutput } from './bundle-output'; import { normalizeFsPath, hasError } from '@utils'; import { optimizeModule } from '../optimize/optimize-module'; +import { STENCIL_INTERNAL_ID } from './entry-alias-ids'; export const workerPlugin = (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx, platform: string, inlineWorkers: boolean): Plugin => { if (platform === 'worker' || platform === 'hydrate') { @@ -248,7 +249,6 @@ addEventListener('message', async ({data}) => { } catch (e) { value = null; - ${isDev ? 'console.error("Error when calling worker routine", e);' : ''} if (e instanceof Error) { err = { isError: true, @@ -279,6 +279,8 @@ addEventListener('message', async ({data}) => { `; export const WORKER_HELPERS = ` +import { consoleError } from '${STENCIL_INTERNAL_ID}'; + let pendingIds = 0; let callbackIds = 0; const pending = new Map(); @@ -299,10 +301,12 @@ export const createWorker = (workerPath, workerName, workerMsgId) => { pending.delete(id); if (err) { - reject((err.isError) + const errObj = (err.isError) ? Object.assign(new Error(err.value.message), err.value) - : err.value - ); + : err.value; + + consoleError(errObj); + reject(errObj); } else { if (callbackIds) { callbackIds.forEach(id => callbacks.delete(id)); @@ -313,7 +317,7 @@ export const createWorker = (workerPath, workerName, workerMsgId) => { try { callbacks.get(id)(...value); } catch (e) { - console.error(e); + consoleError(e); } } }