From 2fbfd9517f52c6ec1a1964bf0c4f73d794f362e5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 26 Jul 2023 10:39:51 +0200 Subject: [PATCH] Remove the unneeded error-handling at the end of `PDFViewerApplication.run` This is quite old code, however the error-handling no longer seems necessary for a couple of reasons: - The `PDFViewerApplication.open` method is asynchronous, which means that it cannot throw a "raw" `Error` and the try-catch is not needed in that case. - None of the other affected methods should throw, and if they do that'd rather indicate an *implementation* error in the code. - Finally, and most importantly, with the `PDFViewerApplication.run` method now being asynchronous an (unlikely) `Error` thrown within it will lead to a rejected `Promise` and not affect execution of other code. --- web/app.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/web/app.js b/web/app.js index c70e3ee96..f4489e956 100644 --- a/web/app.js +++ b/web/app.js @@ -694,7 +694,7 @@ const PDFViewerApplication = { async run(config) { await this.initialize(config); - const { appConfig, eventBus, l10n } = this; + const { appConfig, eventBus } = this; let file; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { const queryString = document.location.search.substring(1); @@ -745,7 +745,7 @@ const PDFViewerApplication = { if (!this.supportsDocumentFonts) { AppOptions.set("disableFontFace", true); - l10n.get("web_fonts_disabled").then(msg => { + this.l10n.get("web_fonts_disabled").then(msg => { console.warn(msg); }); } @@ -775,22 +775,16 @@ const PDFViewerApplication = { true ); - try { - if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - if (file) { - this.open({ url: file }); - } else { - this._hideViewBookmark(); - } - } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { - this.initPassiveLoading(file); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + if (file) { + this.open({ url: file }); } else { - throw new Error("Not implemented: run"); + this._hideViewBookmark(); } - } catch (reason) { - l10n.get("loading_error").then(msg => { - this._documentError(msg, reason); - }); + } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { + this.initPassiveLoading(file); + } else { + throw new Error("Not implemented: run"); } },