Prevent "Uncaught promise" messages in the console when cancelling (some) ReadableStreams

While fixing issue 13794, I noticed that cancelling the `ReadableStream` returned by the `PDFPageProxy.streamTextContent`-method could lead to "Uncaught promise" messages in the console.[1]
Generally speaking, we don't really care about errors when *cancelling* a `ReadableStream` and it thus seems reasonable to simply suppress any output in those cases.

---
[1] Although, after that issue was fixed you'd now need to set the API-option `stopAtErrors = true` to actually trigger this.
This commit is contained in:
Jonas Jenwald 2021-07-30 14:13:02 +02:00
parent 4ad5c5d52a
commit 1df9da949e
2 changed files with 12 additions and 5 deletions

View File

@ -1802,7 +1802,11 @@ class PDFPageProxy {
return; return;
} }
} }
intentState.streamReader.cancel(new AbortException(reason?.message)); intentState.streamReader
.cancel(new AbortException(reason?.message))
.catch(() => {
// Avoid "Uncaught promise" messages in the console.
});
intentState.streamReader = null; intentState.streamReader = null;
if (this._transport.destroyed) { if (this._transport.destroyed) {

View File

@ -597,7 +597,7 @@ class TextLayerRenderTask {
} }
}) })
.catch(() => { .catch(() => {
/* Avoid "Uncaught promise" messages in the console. */ // Avoid "Uncaught promise" messages in the console.
}); });
} }
@ -615,7 +615,11 @@ class TextLayerRenderTask {
cancel() { cancel() {
this._canceled = true; this._canceled = true;
if (this._reader) { if (this._reader) {
this._reader.cancel(new AbortException("TextLayer task cancelled.")); this._reader
.cancel(new AbortException("TextLayer task cancelled."))
.catch(() => {
// Avoid "Uncaught promise" messages in the console.
});
this._reader = null; this._reader = null;
} }
if (this._renderTimer !== null) { if (this._renderTimer !== null) {
@ -741,8 +745,7 @@ class TextLayerRenderTask {
pump(); pump();
} else { } else {
throw new Error( throw new Error(
'Neither "textContent" nor "textContentStream"' + 'Neither "textContent" nor "textContentStream" parameters specified.'
" parameters specified."
); );
} }