Skip to content

Commit

Permalink
Inline worker error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Aug 5, 2024
1 parent e683d10 commit c240537
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/webR/chan/channel-postmessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export class PostMessageChannelMain extends ChannelMain {
reject: (message: string | Error) => void;
close: () => void = () => { return; };
#worker?: Worker;
#workerErrorMessage = "An error occurred initialising the webR PostMessageChannel worker.";

constructor(config: Required<WebROptions>) {
super();
Expand Down Expand Up @@ -59,14 +58,18 @@ export class PostMessageChannelMain extends ChannelMain {
});
(worker as unknown as NodeWorker).on('error', (ev: Event) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR PostMessageChannel worker."
));
});
} else {
worker.onmessage = (ev: MessageEvent) =>
this.#onMessageFromWorker(worker, ev.data as Message);
worker.onerror = (ev) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR PostMessageChannel worker."
));
};
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/webR/chan/channel-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class ServiceWorkerChannelMain extends ChannelMain {
reject: (message: string | Error) => void;
close = () => { return; };

#workerErrorMessage = "An error occurred initialising the webR ServiceWorkerChannel worker.";
#syncMessageCache = new Map<string, Message>();
#registration?: ServiceWorkerRegistration;
#interrupted = false;
Expand Down Expand Up @@ -158,14 +157,18 @@ export class ServiceWorkerChannelMain extends ChannelMain {
});
(worker as unknown as NodeWorker).on('error', (ev: Event) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR ServiceWorkerChannel worker."
));
});
} else {
worker.onmessage = (ev: MessageEvent) =>
this.#onMessageFromWorker(worker, ev.data as Message);
worker.onerror = (ev) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR ServiceWorkerChannel worker."
));
};
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/webR/chan/channel-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if (IN_NODE) {

export class SharedBufferChannelMain extends ChannelMain {
#interruptBuffer?: Int32Array;
#workerErrorMessage = "An error occurred initialising the webR SharedBufferChannel worker.";

initialised: Promise<unknown>;
resolve: (_?: unknown) => void;
Expand Down Expand Up @@ -66,14 +65,18 @@ export class SharedBufferChannelMain extends ChannelMain {
});
(worker as unknown as NodeWorker).on('error', (ev: Event) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR SharedBufferChannel worker."
));
});
} else {
worker.onmessage = (ev: MessageEvent) =>
this.#onMessageFromWorker(worker, ev.data as Message);
worker.onerror = (ev) => {
console.error(ev);
this.reject(new WebRWorkerError(this.#workerErrorMessage));
this.reject(new WebRWorkerError(
"An error occurred initialising the webR SharedBufferChannel worker."
));
};
}
}
Expand Down

0 comments on commit c240537

Please sign in to comment.