Skip to content

Build your personal knowledge base with Trilium Notes

feat(pdf): error handling

Elian Doran84532d42ecc1
diff --git a/src/services/window.ts b/src/services/window.ts
index 5a2dad6c2b..03b24e196b 100644
--- a/src/services/window.ts
+++ b/src/services/window.ts
@@ -71,11 +71,20 @@ ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => {
return;
}
- // TODO: Report if there is an error in generating the PDF.
- const buffer = await browserWindow.webContents.printToPDF({});
+ let buffer: Buffer;
+ try {
+ buffer = await browserWindow.webContents.printToPDF({});
+ } catch (e) {
+ dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-export-message"));
+ return;
+ }
- // TODO: Report if there was an error in saving the PDF.
- fs.writeFileSync(filePath, buffer);
+ try {
+ fs.writeFileSync(filePath, buffer);
+ } catch (e) {
+ dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-save-message"));
+ return;
+ }
shell.openPath(filePath);
});
diff --git a/translations/en/server.json b/translations/en/server.json
index c3ac0dd4a3..5d2d79b9f8 100644
--- a/translations/en/server.json
+++ b/translations/en/server.json
@@ -255,6 +255,9 @@
"note-cannot-be-displayed": "This note type cannot be displayed."
},
"pdf": {
- "export_filter": "PDF Document (*.pdf)"
+ "export_filter": "PDF Document (*.pdf)",
+ "unable-to-export-message": "The current note could not be exported as a PDF.",
+ "unable-to-export-title": "Unable to export as PDF",
+ "unable-to-save-message": "The selected file could not be written to. Try again or select another destination."
}
}