mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
joh/eastern slug (#190250)
* more explicit error handling/logging when post messages fails https://github.com/microsoft/vscode/issues/188347 * print the worker name that fails to send message
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { createTrustedTypesPolicy } from 'vs/base/browser/trustedTypes';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { COI } from 'vs/base/common/network';
|
||||
import { IWorker, IWorkerCallback, IWorkerFactory, logOnceWebWorkerWarning } from 'vs/base/common/worker/simpleWorker';
|
||||
|
||||
@@ -85,11 +86,13 @@ function isPromiseLike<T>(obj: any): obj is PromiseLike<T> {
|
||||
*/
|
||||
class WebWorker implements IWorker {
|
||||
|
||||
private id: number;
|
||||
private readonly id: number;
|
||||
private readonly label: string;
|
||||
private worker: Promise<Worker> | null;
|
||||
|
||||
constructor(moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
|
||||
this.id = id;
|
||||
this.label = label;
|
||||
const workerOrPromise = getWorker(label);
|
||||
if (isPromiseLike(workerOrPromise)) {
|
||||
this.worker = workerOrPromise;
|
||||
@@ -113,7 +116,14 @@ class WebWorker implements IWorker {
|
||||
}
|
||||
|
||||
public postMessage(message: any, transfer: Transferable[]): void {
|
||||
this.worker?.then(w => w.postMessage(message, transfer));
|
||||
this.worker?.then(w => {
|
||||
try {
|
||||
w.postMessage(message, transfer);
|
||||
} catch (err) {
|
||||
onUnexpectedError(err);
|
||||
onUnexpectedError(new Error(`FAILED to post message to '${this.label}'-worker`, { cause: err }));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
Reference in New Issue
Block a user