Skip to content

Build your personal knowledge base with Trilium Notes

feat(script): improve script error message

Elian Doran19cd7a0cad97
diff --git a/apps/client/src/services/bundle.ts b/apps/client/src/services/bundle.ts
index a56139d369..d33ba76a0a 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 641b3cdcee..f31e242cdd 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 7f34841f8a..9cfc8b2e15 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",