Fix Worker was terminated error when loading is cancelled

Fixes https://github.com/mozilla/pdf.js/issues/11595, where cancelling loading with `loadingTask.destroy()` before it finishes throws a `Worker was terminated` error that CANNOT be caught.

When worker is terminated, an error is thrown here:

6c746260a9/src/core/worker.js (L374)

Then `onFailure` runs, in which we throw again via `ensureNotTerminated()`. However, this second error is never caught (and cannot be), resulting in console spam.

There is no need to throw any additional errors since the termination is already reported [here](6c746260a9/src/core/worker.js (L371-L373)), and `onFailure` is supposed to handle errors, not throw them.
This commit is contained in:
Andrii Vitiv 2025-12-14 18:06:33 +02:00
parent 6c746260a9
commit 9677798ba0
No known key found for this signature in database
GPG Key ID: EC03902B4A941DFA

View File

@ -319,7 +319,9 @@ class WorkerMessageHandler {
}
function onFailure(ex) {
ensureNotTerminated();
if (terminated) {
return;
}
if (ex instanceof PasswordException) {
const task = new WorkerTask(`PasswordException: response ${ex.code}`);