Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/client/client-log.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
14 changes: 9 additions & 5 deletions src/compiler/bundle/worker-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -313,7 +317,7 @@ export const createWorker = (workerPath, workerName, workerMsgId) => {
try {
callbacks.get(id)(...value);
} catch (e) {
console.error(e);
consoleError(e);
}
}
}
Expand Down