improvements to error logging in frontend

This commit is contained in:
zadam 2020-10-12 21:05:34 +02:00
parent c71ac0302a
commit d953d96fa6
12 changed files with 30 additions and 21 deletions

View File

@ -86,7 +86,7 @@ $form.on('submit', () => {
textTypeWidget.addLink(notePath, linkTitle); textTypeWidget.addLink(notePath, linkTitle);
} }
else { else {
console.error("No path to add link."); logError("No path to add link.");
} }
return false; return false;

View File

@ -61,7 +61,7 @@ $form.on('submit', () => {
cloneNotesTo(notePath); cloneNotesTo(notePath);
} }
else { else {
console.error("No path to clone to."); logError("No path to clone to.");
} }
return false; return false;

View File

@ -46,7 +46,7 @@ $form.on('submit', () => {
includeNote(notePath); includeNote(notePath);
} }
else { else {
console.error("No noteId to include."); logError("No noteId to include.");
} }
return false; return false;

View File

@ -51,7 +51,7 @@ $form.on('submit', () => {
treeCache.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId)); treeCache.getBranchId(parentNoteId, noteId).then(branchId => moveNotesTo(branchId));
} }
else { else {
console.error("No path to move to."); logError("No path to move to.");
} }
return false; return false;

View File

@ -64,7 +64,7 @@ async function getWidgetBundlesByParent() {
widget = await executeBundle(bundle); widget = await executeBundle(bundle);
} }
catch (e) { catch (e) {
console.error("Widget initialization failed: ", e); logError("Widget initialization failed: ", e);
continue; continue;
} }

View File

@ -11,7 +11,7 @@ function getNotePathFromUrl(url) {
async function createNoteLink(notePath, options = {}) { async function createNoteLink(notePath, options = {}) {
if (!notePath || !notePath.trim()) { if (!notePath || !notePath.trim()) {
console.error("Missing note path"); logError("Missing note path");
return $("<span>").text("[missing note]"); return $("<span>").text("[missing note]");
} }

View File

@ -36,7 +36,7 @@ class TabContext extends Component {
resolvedNotePath = await treeService.resolveNotePath(inputNotePath); resolvedNotePath = await treeService.resolveNotePath(inputNotePath);
if (!resolvedNotePath) { if (!resolvedNotePath) {
console.error(`Cannot resolve note path ${inputNotePath}`); logError(`Cannot resolve note path ${inputNotePath}`);
return; return;
} }

View File

@ -62,7 +62,7 @@ async function resolveNotePathToSegments(notePath, logErrors = true) {
if (!parents.length) { if (!parents.length) {
if (logErrors) { if (logErrors) {
ws.logError(`No parents found for ${childNoteId}`); ws.logError(`No parents found for ${childNoteId} (${child.title})`);
} }
return; return;
@ -70,7 +70,9 @@ async function resolveNotePathToSegments(notePath, logErrors = true) {
if (!parents.some(p => p.noteId === parentNoteId)) { if (!parents.some(p => p.noteId === parentNoteId)) {
if (logErrors) { 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]); const someNotePath = getSomeNotePath(parents[0]);
@ -113,7 +115,7 @@ function getSomeNotePath(note) {
const parents = cur.getParentNotes(); const parents = cur.getParentNotes();
if (!parents.length) { if (!parents.length) {
console.error(`Can't find parents for note ${cur.noteId}`); logError(`Can't find parents for note ${cur.noteId}`);
return; return;
} }
@ -196,7 +198,7 @@ function getNoteIdAndParentIdFromNotePath(notePath) {
function getNotePath(node) { function getNotePath(node) {
if (!node) { if (!node) {
console.error("Node is null"); logError("Node is null");
return ""; return "";
} }

View File

@ -267,7 +267,7 @@ class TreeCache {
getBranch(branchId, silentNotFoundError = false) { getBranch(branchId, silentNotFoundError = false) {
if (!(branchId in this.branches)) { if (!(branchId in this.branches)) {
if (!silentNotFoundError) { if (!silentNotFoundError) {
console.error(`Not existing branch ${branchId}`); logError(`Not existing branch ${branchId}`);
} }
} }
else { else {
@ -283,7 +283,7 @@ class TreeCache {
const child = await this.getNote(childNoteId); const child = await this.getNote(childNoteId);
if (!child) { 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; return null;
} }

View File

@ -19,8 +19,7 @@ let lastPingTs;
let syncDataQueue = []; let syncDataQueue = [];
function logError(message) { function logError(message) {
console.log(utils.now(), message); // needs to be separate from .trace() console.error(utils.now(), message); // needs to be separate from .trace()
console.trace();
if (ws && ws.readyState === 1) { if (ws && ws.readyState === 1) {
ws.send(JSON.stringify({ ws.send(JSON.stringify({
@ -31,6 +30,8 @@ function logError(message) {
} }
} }
window.logError = logError;
function subscribeToMessages(messageHandler) { function subscribeToMessages(messageHandler) {
messageHandlers.push(messageHandler); messageHandlers.push(messageHandler);
} }

View File

@ -406,7 +406,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
notes = JSON.parse(jsonStr); notes = JSON.parse(jsonStr);
} }
catch (e) { catch (e) {
console.error(`Cannot parse ${jsonStr} into notes for drop`); logError(`Cannot parse ${jsonStr} into notes for drop`);
return; return;
} }
@ -809,7 +809,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
if (!resolvedNotePathSegments) { if (!resolvedNotePathSegments) {
if (logErrors) { if (logErrors) {
console.error("Could not find run path for notePath:", notePath); logError("Could not find run path for notePath:", notePath);
} }
return; return;
@ -1152,11 +1152,17 @@ export default class NoteTreeWidget extends TabAwareWidget {
async setExpanded(branchId, isExpanded) { async setExpanded(branchId, isExpanded) {
utils.assertArguments(branchId); utils.assertArguments(branchId);
const branch = treeCache.getBranch(branchId); const branch = treeCache.getBranch(branchId, true);
if (!branch) { if (!branch) {
// in case of virtual branches there's nothing to update if (branchId && branchId.startsWith('virt')) {
return; // in case of virtual branches there's nothing to update
return;
}
else {
logError(`Cannot find branch=${branchId}`);
return;
}
} }
branch.isExpanded = isExpanded; branch.isExpanded = isExpanded;

View File

@ -539,7 +539,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
const note = this.mapData.notes.find(note => note.noteId === noteId); const note = this.mapData.notes.find(note => note.noteId === noteId);
if (!note) { if (!note) {
console.error(`Note ${noteId} not found!`); logError(`Note ${noteId} not found!`);
return; return;
} }