client: Improve logging for some bundle errors

This commit is contained in:
Elian Doran
2024-10-24 20:55:21 +03:00
parent 81ca0a3776
commit eee088316d
3 changed files with 19 additions and 2 deletions

View File

@@ -9,9 +9,9 @@ import electronContextMenu from "./menus/electron_context_menu.js";
import glob from "./services/glob.js"; import glob from "./services/glob.js";
import { t } from "./services/i18n.js"; import { t } from "./services/i18n.js";
await appContext.earlyInit();
bundleService.getWidgetBundlesByParent().then(async widgetBundles => { bundleService.getWidgetBundlesByParent().then(async widgetBundles => {
await appContext.earlyInit();
// A dynamic import is required for layouts since they initialize components which require translations. // A dynamic import is required for layouts since they initialize components which require translations.
const DesktopLayout = (await import("./layouts/desktop_layout.js")).default; const DesktopLayout = (await import("./layouts/desktop_layout.js")).default;

View File

@@ -3,6 +3,7 @@ import server from "./server.js";
import toastService from "./toast.js"; import toastService from "./toast.js";
import froca from "./froca.js"; import froca from "./froca.js";
import utils from "./utils.js"; import utils from "./utils.js";
import { t } from "./i18n.js";
async function getAndExecuteBundle(noteId, originEntity = null, script = null, params = null) { async function getAndExecuteBundle(noteId, originEntity = null, script = null, params = null) {
const bundle = await server.post(`script/bundle/${noteId}`, { const bundle = await server.post(`script/bundle/${noteId}`, {
@@ -79,6 +80,18 @@ async function getWidgetBundlesByParent() {
widgetsByParent.add(widget); widgetsByParent.add(widget);
} }
catch (e) { catch (e) {
const noteId = bundle.noteId;
const note = await froca.getNote(noteId);
toastService.showPersistent({
title: t("toast.bundle-error.title"),
icon: "alert",
message: t("toast.bundle-error.message", {
id: noteId,
title: note.title,
message: e.message
})
});
logError("Widget initialization failed: ", e); logError("Widget initialization failed: ", e);
continue; continue;
} }

View File

@@ -18,6 +18,10 @@
"title": "Failed to initialize a widget", "title": "Failed to initialize a widget",
"message-custom": "Custom widget from note with ID \"{{id}}\", titled \"{{title}}\" could not be initialized due to:\n\n{{message}}", "message-custom": "Custom widget from note with ID \"{{id}}\", titled \"{{title}}\" could not be initialized due to:\n\n{{message}}",
"message-unknown": "Unknown widget could not be initialized due to:\n\n{{message}}" "message-unknown": "Unknown widget could not be initialized due to:\n\n{{message}}"
},
"bundle-error": {
"title": "Failed to load a custom script",
"message": "Script from note with ID \"{{id}}\", titled \"{{title}}\" could not be executed due to:\n\n{{message}}"
} }
}, },
"add_link": { "add_link": {