Skip to content

Commit

Permalink
Fix uncaught error if worker can't be initialized
Browse files Browse the repository at this point in the history
Related to #19, this "fixes" an unactionable global uncaught error in
case the xmllint worker could not be initialized for whatever reason.

This patch should not cause runtime application code differences,
because the error that this case created would've already been swallowed
by the earlier error (as per how Promise.finally works on rejected
Promise), but it did create a confusing error to logs / global error
handler.
  • Loading branch information
noppa committed Sep 30, 2023
1 parent eb6a607 commit 012dde3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ function validateXML(options) {
addEventListener('message', onmessage);
addEventListener('error', onerror);
worker.postMessage(preprocessedOptions);
}).finally(() => worker.terminate());
}).finally(() => {
if (worker) {
return worker.terminate();
}
});
}

// #ifdef browser
Expand Down

0 comments on commit 012dde3

Please sign in to comment.