From 19cd7a0cad97421e211d2e05718c715a9dcb35be Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 23 Dec 2025 23:02:15 +0200 Subject: [PATCH] feat(script): improve script error message --- apps/client/src/services/bundle.ts | 24 ++----------------- apps/client/src/services/toast.ts | 2 +- .../src/translations/en/translation.json | 5 ++-- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts index a56139d36..d33ba76a0 100644 --- a/apps/client/src/services/bundle.ts +++ b/apps/client/src/services/bundle.ts @@ -46,17 +46,7 @@ export async function executeBundle(bundle: Bundle, originEntity?: Entity | null return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`); }.call(apiContext); } catch (e: any) { - const note = await froca.getNote(bundle.noteId); - toastService.showPersistent({ - id: `custom-script-failure-${note?.noteId}`, - title: t("toast.bundle-error.title"), - icon: "bx bx-error-circle", - message: t("toast.bundle-error.message", { - id: note?.noteId, - title: note?.title, - message: e.message - }) - }); + showErrorForScriptNote(bundle.noteId, t("toast.bundle-error.message", { message: e.message })); logError("Widget initialization failed: ", e); } } @@ -151,17 +141,7 @@ async function getWidgetBundlesByParent() { } } catch (e: any) { const noteId = bundle.noteId; - const note = await froca.getNote(noteId); - toastService.showPersistent({ - id: `custom-script-failure-${noteId}`, - title: t("toast.bundle-error.title"), - icon: "bx bx-error-circle", - message: t("toast.bundle-error.message", { - id: noteId, - title: note?.title, - message: e.message - }) - }); + showErrorForScriptNote(noteId, t("toast.bundle-error.message", { message: e.message })); logError("Widget initialization failed: ", e); continue; diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.ts index 641b3cdce..f31e242cd 100644 --- a/apps/client/src/services/toast.ts +++ b/apps/client/src/services/toast.ts @@ -69,7 +69,7 @@ export async function showErrorForScriptNote(noteId: string, message: string) { showPersistent({ id: `custom-widget-failure-${noteId}`, - title: note?.title ?? "", + title: t("toast.scripting-error", { title: note?.title ?? "" }), icon: note?.getIcon() ?? "bx bx-error-circle", message, timeout: 15_000, diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json index 7f34841f8..9cfc8b2e1 100644 --- a/apps/client/src/translations/en/translation.json +++ b/apps/client/src/translations/en/translation.json @@ -21,7 +21,7 @@ }, "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}}" + "message": "Script could not be executed due to:\n\n{{message}}" }, "widget-list-error": { "title": "Failed to obtain the list of widgets from the server" @@ -30,7 +30,8 @@ "title": "Failed to render a custom React widget" }, "widget-missing-parent": "Custom widget does not have mandatory '{{property}}' property defined.", - "open-script-note": "Open script note" + "open-script-note": "Open script note", + "scripting-error": "Custom script error: {{title}}" }, "add_link": { "add_link": "Add link",