Ensure that the viewer handles BaseViewer initialization failures

*This patch can be tested e.g. with the `poppler-85140-0.pdf` document from the test-suite.*

For some sufficiently corrupt documents the `getDocument` call will succeed, but fetching even the very first page fails. Currently we only print error messages (in the console) from the `{BaseViewer, PDFThumbnailViewer}.setDocument` methods, but don't actually provide these errors to allow the viewer to handle them properly.
In practice this means that the GENERIC viewer won't display the `errorWrapper`, and in the MOZCENTRAL viewer the *browser* loading indicator is never hidden (since we never unblock the "load" event).
This commit is contained in:
Jonas Jenwald 2021-12-04 16:40:48 +01:00
parent dc455c836e
commit 9de30c4ff0
2 changed files with 27 additions and 16 deletions

View file

@ -530,12 +530,14 @@ class BaseViewer {
this.eventBus.dispatch("scrollmodechanged", { source: this, mode });
}
this._pagesCapability.promise.then(() => {
this.eventBus.dispatch("pagesloaded", {
source: this,
pagesCount,
});
});
this._pagesCapability.promise.then(
() => {
this.eventBus.dispatch("pagesloaded", { source: this, pagesCount });
},
() => {
/* Prevent "Uncaught (in promise)"-messages in the console. */
}
);
this._onBeforeDraw = evt => {
const pageView = this._pages[evt.pageNumber - 1];
@ -680,6 +682,8 @@ class BaseViewer {
})
.catch(reason => {
console.error("Unable to initialize viewer", reason);
this._pagesCapability.reject(reason);
});
}