Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
improvements to error logging in frontend
zadamd953d96fa61b
diff --git a/src/public/app/dialogs/add_link.js b/src/public/app/dialogs/add_link.jsindex 13798a3c6e..4f29bb39a1 100644--- a/src/public/app/dialogs/add_link.js+++ b/src/public/app/dialogs/add_link.js@@ -86,7 +86,7 @@ $form.on('submit', () => {textTypeWidget.addLink(notePath, linkTitle);}else {- console.error("No path to add link.");+ logError("No path to add link.");}return false;diff --git a/src/public/app/dialogs/clone_to.js b/src/public/app/dialogs/clone_to.jsindex de82c50b5a..6ac6af4225 100644--- a/src/public/app/dialogs/clone_to.js+++ b/src/public/app/dialogs/clone_to.js@@ -61,7 +61,7 @@ $form.on('submit', () => {cloneNotesTo(notePath);}else {- console.error("No path to clone to.");+ logError("No path to clone to.");}return false;diff --git a/src/public/app/dialogs/include_note.js b/src/public/app/dialogs/include_note.jsindex 1aa2b149ed..9f92c3a92a 100644--- a/src/public/app/dialogs/include_note.js+++ b/src/public/app/dialogs/include_note.js@@ -46,7 +46,7 @@ $form.on('submit', () => {includeNote(notePath);}else {- console.error("No noteId to include.");+ logError("No noteId to include.");}return false;diff --git a/src/public/app/dialogs/move_to.js b/src/public/app/dialogs/move_to.jsindex 21b2ebdd88..9d5408818b 100644--- a/src/public/app/dialogs/move_to.js+++ b/src/public/app/dialogs/move_to.js@@ -51,7 +51,7 @@ $form.on('submit', () => {treeCache.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId));}else {- console.error("No path to move to.");+ logError("No path to move to.");}return false;diff --git a/src/public/app/services/bundle.js b/src/public/app/services/bundle.jsindex 691562b699..1ab93ded89 100644--- a/src/public/app/services/bundle.js+++ b/src/public/app/services/bundle.js@@ -64,7 +64,7 @@ async function getWidgetBundlesByParent() {widget = await executeBundle(bundle);}catch (e) {- console.error("Widget initialization failed: ", e);+ logError("Widget initialization failed: ", e);continue;}diff --git a/src/public/app/services/link.js b/src/public/app/services/link.jsindex 2ff1485fa8..aefc42efde 100644--- a/src/public/app/services/link.js+++ b/src/public/app/services/link.js@@ -11,7 +11,7 @@ function getNotePathFromUrl(url) {async function createNoteLink(notePath, options = {}) {if (!notePath || !notePath.trim()) {- console.error("Missing note path");+ logError("Missing note path");return $("<span>").text("[missing note]");}diff --git a/src/public/app/services/tab_context.js b/src/public/app/services/tab_context.jsindex d47a477211..196a52cfe5 100644--- a/src/public/app/services/tab_context.js+++ b/src/public/app/services/tab_context.js@@ -36,7 +36,7 @@ class TabContext extends Component {resolvedNotePath = await treeService.resolveNotePath(inputNotePath);if (!resolvedNotePath) {- console.error(`Cannot resolve note path ${inputNotePath}`);+ logError(`Cannot resolve note path ${inputNotePath}`);return;}diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.jsindex bc1b3e0a75..8e285c5e65 100644--- a/src/public/app/services/tree.js+++ b/src/public/app/services/tree.js@@ -62,7 +62,7 @@ async function resolveNotePathToSegments(notePath, logErrors = true) {if (!parents.length) {if (logErrors) {- ws.logError(`No parents found for ${childNoteId}`);+ ws.logError(`No parents found for ${childNoteId} (${child.title})`);}return;@@ -70,7 +70,9 @@ async function resolveNotePathToSegments(notePath, logErrors = true) {if (!parents.some(p => p.noteId === parentNoteId)) {if (logErrors) {- console.log(utils.now(), `Did not find parent ${parentNoteId} for child ${childNoteId}, available parents: ${parents.map(p => p.noteId)}`);+ const parent = treeCache.getNoteFromCache(parentNoteId);++ console.log(utils.now(), `Did not find parent ${parentNoteId} (${parent ? parent.title : 'n/a'}) for child ${childNoteId} (${child.title}), available parents: ${parents.map(p => `${p.noteId} (${p.title})`)}`);}const someNotePath = getSomeNotePath(parents[0]);@@ -113,7 +115,7 @@ function getSomeNotePath(note) {const parents = cur.getParentNotes();if (!parents.length) {- console.error(`Can't find parents for note ${cur.noteId}`);+ logError(`Can't find parents for note ${cur.noteId}`);return;}@@ -196,7 +198,7 @@ function getNoteIdAndParentIdFromNotePath(notePath) {function getNotePath(node) {if (!node) {- console.error("Node is null");+ logError("Node is null");return "";}diff --git a/src/public/app/services/tree_cache.js b/src/public/app/services/tree_cache.jsindex 27815d4d8d..ad642e89c1 100644--- a/src/public/app/services/tree_cache.js+++ b/src/public/app/services/tree_cache.js@@ -267,7 +267,7 @@ class TreeCache {getBranch(branchId, silentNotFoundError = false) {if (!(branchId in this.branches)) {if (!silentNotFoundError) {- console.error(`Not existing branch ${branchId}`);+ logError(`Not existing branch ${branchId}`);}}else {@@ -283,7 +283,7 @@ class TreeCache {const child = await this.getNote(childNoteId);if (!child) {- console.error(`Could not find branchId for parent=${parentNoteId}, child=${childNoteId} since child does not exist`);+ logError(`Could not find branchId for parent=${parentNoteId}, child=${childNoteId} since child does not exist`);return null;}diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.jsindex ad66eeb421..afcff6216e 100644--- a/src/public/app/services/ws.js+++ b/src/public/app/services/ws.js@@ -19,8 +19,7 @@ let lastPingTs;let syncDataQueue = [];function logError(message) {- console.log(utils.now(), message); // needs to be separate from .trace()- console.trace();+ console.error(utils.now(), message); // needs to be separate from .trace()if (ws && ws.readyState === 1) {ws.send(JSON.stringify({@@ -31,6 +30,8 @@ function logError(message) {}}+window.logError = logError;+function subscribeToMessages(messageHandler) {messageHandlers.push(messageHandler);}diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex f0627db58d..39e4b52be5 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -406,7 +406,7 @@ export default class NoteTreeWidget extends TabAwareWidget {notes = JSON.parse(jsonStr);}catch (e) {- console.error(`Cannot parse ${jsonStr} into notes for drop`);+ logError(`Cannot parse ${jsonStr} into notes for drop`);return;}@@ -809,7 +809,7 @@ export default class NoteTreeWidget extends TabAwareWidget {if (!resolvedNotePathSegments) {if (logErrors) {- console.error("Could not find run path for notePath:", notePath);+ logError("Could not find run path for notePath:", notePath);}return;@@ -1152,11 +1152,17 @@ export default class NoteTreeWidget extends TabAwareWidget {async setExpanded(branchId, isExpanded) {utils.assertArguments(branchId);- const branch = treeCache.getBranch(branchId);+ const branch = treeCache.getBranch(branchId, true);if (!branch) {- // in case of virtual branches there's nothing to update- return;+ if (branchId && branchId.startsWith('virt')) {+ // in case of virtual branches there's nothing to update+ return;+ }+ else {+ logError(`Cannot find branch=${branchId}`);+ return;+ }}branch.isExpanded = isExpanded;diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.jsindex 0c01e1e437..dbb7d0516e 100644--- a/src/public/app/widgets/type_widgets/relation_map.js+++ b/src/public/app/widgets/type_widgets/relation_map.js@@ -539,7 +539,7 @@ export default class RelationMapTypeWidget extends TypeWidget {const note = this.mapData.notes.find(note => note.noteId === noteId);if (!note) {- console.error(`Note ${noteId} not found!`);+ logError(`Note ${noteId} not found!`);return;}