mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-04-25 22:29:25 -05:00
better logging and notifications on script errors for easier debugging
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import ScriptContext from "./script_context.js";
|
||||
import server from "./server.js";
|
||||
import infoService from "./info.js";
|
||||
|
||||
async function getAndExecuteBundle(noteId, originEntity = null) {
|
||||
const bundle = await server.get('script/bundle/' + noteId);
|
||||
@@ -10,9 +11,14 @@ async function getAndExecuteBundle(noteId, originEntity = null) {
|
||||
async function executeBundle(bundle, originEntity) {
|
||||
const apiContext = ScriptContext(bundle.note, bundle.allNotes, originEntity);
|
||||
|
||||
return await (function () {
|
||||
return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`);
|
||||
}.call(apiContext));
|
||||
try {
|
||||
return await (function () {
|
||||
return eval(`const apiContext = this; (async function() { ${bundle.script}\r\n})()`);
|
||||
}.call(apiContext));
|
||||
}
|
||||
catch (e) {
|
||||
infoService.showAndLogError(`Execution of script "${bundle.note.title}" (${bundle.note.noteId}) failed with error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function executeStartupBundles() {
|
||||
|
||||
@@ -14,6 +14,12 @@ function showMessage(message) {
|
||||
});
|
||||
}
|
||||
|
||||
function showAndLogError(message, delay = 10000) {
|
||||
showError(message, delay);
|
||||
|
||||
messagingService.logError(message);
|
||||
}
|
||||
|
||||
function showError(message, delay = 10000) {
|
||||
console.log(utils.now(), "error: ", message);
|
||||
|
||||
@@ -36,5 +42,6 @@ function throwError(message) {
|
||||
export default {
|
||||
showMessage,
|
||||
showError,
|
||||
showAndLogError,
|
||||
throwError
|
||||
}
|
||||
@@ -72,7 +72,12 @@ function ScriptApi(startNote, currentNote, originEntity = null) {
|
||||
originEntityId: originEntity ? originEntity.noteId : null
|
||||
});
|
||||
|
||||
return ret.executionResult;
|
||||
if (ret.success) {
|
||||
return ret.executionResult;
|
||||
}
|
||||
else {
|
||||
throw new Error("server error: " + ret.error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user