mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Do not stringify errors when logging them
Converting errors to string drops their stack trace, making it more difficult to debug their actual reason. We can instead pass the error objects as-is to console.warn/error, so that Firefox/Chrome devtools will show both the stack trace of the console.warn/error call, and the original stack trace of the error. This commit also enables the `unicorn/no-console-spaces` ESLint rule, which avoids accidental extra spaces when passing multiple parameters to `console.*` methods.
This commit is contained in:
parent
d448953166
commit
202b26487f
12 changed files with 21 additions and 20 deletions
|
@ -112,6 +112,7 @@ export default [
|
||||||
"perfectionist/sort-named-exports": "error",
|
"perfectionist/sort-named-exports": "error",
|
||||||
"unicorn/no-abusive-eslint-disable": "error",
|
"unicorn/no-abusive-eslint-disable": "error",
|
||||||
"unicorn/no-array-push-push": "error",
|
"unicorn/no-array-push-push": "error",
|
||||||
|
"unicorn/no-console-spaces": "error",
|
||||||
"unicorn/no-instanceof-array": "error",
|
"unicorn/no-instanceof-array": "error",
|
||||||
"unicorn/no-invalid-remove-event-listener": "error",
|
"unicorn/no-invalid-remove-event-listener": "error",
|
||||||
"unicorn/no-new-buffer": "error",
|
"unicorn/no-new-buffer": "error",
|
||||||
|
|
|
@ -86,7 +86,7 @@ async function downloadManifestFiles(manifest) {
|
||||||
try {
|
try {
|
||||||
await downloadFile(file, url);
|
await downloadFile(file, url);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`Error during downloading of ${url}: ${ex}`);
|
console.error(`Error during downloading of ${url}:`, ex);
|
||||||
fs.writeFileSync(file, ""); // making it empty file
|
fs.writeFileSync(file, ""); // making it empty file
|
||||||
fs.writeFileSync(`${file}.error`, ex);
|
fs.writeFileSync(`${file}.error`, ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1192,7 +1192,7 @@ class Driver {
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.warn(`Driver._send failed (${url}): ${reason}`);
|
console.warn(`Driver._send failed (${url}):`, reason);
|
||||||
|
|
||||||
this.inFlightRequests--;
|
this.inFlightRequests--;
|
||||||
resolve();
|
resolve();
|
||||||
|
|
|
@ -18,7 +18,7 @@ const TestReporter = function (browser) {
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.warn(`TestReporter - send failed (${action}): ${reason}`);
|
console.warn(`TestReporter - send failed (${action}):`, reason);
|
||||||
resolve();
|
resolve();
|
||||||
|
|
||||||
send(action, json);
|
send(action, json);
|
||||||
|
|
10
web/app.js
10
web/app.js
|
@ -202,7 +202,7 @@ const PDFViewerApplication = {
|
||||||
try {
|
try {
|
||||||
await this.preferences.initializedPromise;
|
await this.preferences.initializedPromise;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`initialize: "${ex.message}".`);
|
console.error("initialize:", ex);
|
||||||
}
|
}
|
||||||
if (AppOptions.get("pdfBugEnabled")) {
|
if (AppOptions.get("pdfBugEnabled")) {
|
||||||
await this._parseHashParams();
|
await this._parseHashParams();
|
||||||
|
@ -306,7 +306,7 @@ const PDFViewerApplication = {
|
||||||
await __non_webpack_import__(PDFWorker.workerSrc);
|
await __non_webpack_import__(PDFWorker.workerSrc);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`_parseHashParams: "${ex.message}".`);
|
console.error("_parseHashParams:", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params.has("textlayer")) {
|
if (params.has("textlayer")) {
|
||||||
|
@ -322,7 +322,7 @@ const PDFViewerApplication = {
|
||||||
await loadPDFBug();
|
await loadPDFBug();
|
||||||
this._PDFBug.loadCSS();
|
this._PDFBug.loadCSS();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`_parseHashParams: "${ex.message}".`);
|
console.error("_parseHashParams:", ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ const PDFViewerApplication = {
|
||||||
await loadPDFBug();
|
await loadPDFBug();
|
||||||
this._PDFBug.init(mainContainer, enabled);
|
this._PDFBug.init(mainContainer, enabled);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`_parseHashParams: "${ex.message}".`);
|
console.error("_parseHashParams:", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// It is not possible to change locale for the (various) extension builds.
|
// It is not possible to change locale for the (various) extension builds.
|
||||||
|
@ -1121,7 +1121,7 @@ const PDFViewerApplication = {
|
||||||
this.downloadManager.download(data, this._downloadUrl, this._docFilename);
|
this.downloadManager.download(data, this._downloadUrl, this._docFilename);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
// When the PDF document isn't ready, fallback to a "regular" download.
|
// When the PDF document isn't ready, fallback to a "regular" download.
|
||||||
console.error(`Error when saving the document: ${reason.message}`);
|
console.error(`Error when saving the document:`, reason);
|
||||||
await this.download();
|
await this.download();
|
||||||
} finally {
|
} finally {
|
||||||
await this.pdfScriptingManager.dispatchDidSave();
|
await this.pdfScriptingManager.dispatchDidSave();
|
||||||
|
|
|
@ -93,7 +93,7 @@ class DownloadManager {
|
||||||
window.open(viewerUrl);
|
window.open(viewerUrl);
|
||||||
return true;
|
return true;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`openOrDownloadData: ${ex}`);
|
console.error("openOrDownloadData:", ex);
|
||||||
// Release the `blobUrl`, since opening it failed, and fallback to
|
// Release the `blobUrl`, since opening it failed, and fallback to
|
||||||
// downloading the PDF file.
|
// downloading the PDF file.
|
||||||
URL.revokeObjectURL(blobUrl);
|
URL.revokeObjectURL(blobUrl);
|
||||||
|
|
|
@ -121,7 +121,7 @@ class DownloadManager {
|
||||||
window.open(viewerUrl);
|
window.open(viewerUrl);
|
||||||
return true;
|
return true;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`openOrDownloadData: ${ex}`);
|
console.error("openOrDownloadData:", ex);
|
||||||
// Release the `blobUrl`, since opening it failed, and fallback to
|
// Release the `blobUrl`, since opening it failed, and fallback to
|
||||||
// downloading the PDF file.
|
// downloading the PDF file.
|
||||||
URL.revokeObjectURL(blobUrl);
|
URL.revokeObjectURL(blobUrl);
|
||||||
|
|
|
@ -85,7 +85,7 @@ class L10n {
|
||||||
try {
|
try {
|
||||||
await this.#l10n.translateElements([element]);
|
await this.#l10n.translateElements([element]);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`translateOnce: "${ex}".`);
|
console.error("translateOnce:", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -401,7 +401,7 @@ class PDFPageView {
|
||||||
"display"
|
"display"
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`#renderAnnotationLayer: "${ex}".`);
|
console.error("#renderAnnotationLayer:", ex);
|
||||||
error = ex;
|
error = ex;
|
||||||
} finally {
|
} finally {
|
||||||
this.#dispatchLayerRendered("annotationlayerrendered", error);
|
this.#dispatchLayerRendered("annotationlayerrendered", error);
|
||||||
|
@ -413,7 +413,7 @@ class PDFPageView {
|
||||||
try {
|
try {
|
||||||
await this.annotationEditorLayer.render(this.viewport, "display");
|
await this.annotationEditorLayer.render(this.viewport, "display");
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`#renderAnnotationEditorLayer: "${ex}".`);
|
console.error("#renderAnnotationEditorLayer:", ex);
|
||||||
error = ex;
|
error = ex;
|
||||||
} finally {
|
} finally {
|
||||||
this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
|
this.#dispatchLayerRendered("annotationeditorlayerrendered", error);
|
||||||
|
@ -424,7 +424,7 @@ class PDFPageView {
|
||||||
try {
|
try {
|
||||||
await this.drawLayer.render("display");
|
await this.drawLayer.render("display");
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`#renderDrawLayer: "${ex}".`);
|
console.error("#renderDrawLayer:", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ class PDFPageView {
|
||||||
this.#buildXfaTextContentItems(result.textDivs);
|
this.#buildXfaTextContentItems(result.textDivs);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(`#renderXfaLayer: "${ex}".`);
|
console.error("#renderXfaLayer:", ex);
|
||||||
error = ex;
|
error = ex;
|
||||||
} finally {
|
} finally {
|
||||||
if (this.xfaLayer?.div) {
|
if (this.xfaLayer?.div) {
|
||||||
|
@ -465,7 +465,7 @@ class PDFPageView {
|
||||||
if (ex instanceof AbortException) {
|
if (ex instanceof AbortException) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error(`#renderTextLayer: "${ex}".`);
|
console.error("#renderTextLayer:", ex);
|
||||||
error = ex;
|
error = ex;
|
||||||
}
|
}
|
||||||
this.#dispatchLayerRendered("textlayerrendered", error);
|
this.#dispatchLayerRendered("textlayerrendered", error);
|
||||||
|
|
|
@ -201,7 +201,7 @@ class PDFRenderingQueue {
|
||||||
if (reason instanceof RenderingCancelledException) {
|
if (reason instanceof RenderingCancelledException) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error(`renderView: "${reason}"`);
|
console.error("renderView:", reason);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ class PDFScriptingManager {
|
||||||
try {
|
try {
|
||||||
this.#scripting = this.#initScripting();
|
this.#scripting = this.#initScripting();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`setDocument: "${error.message}".`);
|
console.error("setDocument:", error);
|
||||||
|
|
||||||
await this.#destroyScripting();
|
await this.#destroyScripting();
|
||||||
return;
|
return;
|
||||||
|
@ -192,7 +192,7 @@ class PDFScriptingManager {
|
||||||
|
|
||||||
eventBus.dispatch("sandboxcreated", { source: this });
|
eventBus.dispatch("sandboxcreated", { source: this });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`setDocument: "${error.message}".`);
|
console.error("setDocument:", error);
|
||||||
|
|
||||||
await this.#destroyScripting();
|
await this.#destroyScripting();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -248,7 +248,7 @@ function webViewerLoad() {
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// The viewer could be in e.g. a cross-origin <iframe> element,
|
// The viewer could be in e.g. a cross-origin <iframe> element,
|
||||||
// fallback to dispatching the event at the current `document`.
|
// fallback to dispatching the event at the current `document`.
|
||||||
console.error(`webviewerloaded: ${ex}`);
|
console.error("webviewerloaded:", ex);
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue