From 33571e0ef3a3baa74dbbff81079cdefd27533ce0 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 9 Dec 2020 22:49:55 +0100 Subject: [PATCH] better logging for un/protect errors --- src/services/consistency_checks.js | 2 +- src/services/note_revisions.js | 18 +++++++++++++----- src/services/notes.js | 21 ++++++++++++++------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 07c6d9679..705431bc4 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -650,7 +650,7 @@ class ConsistencyChecks { // root branch should always be expanded sql.execute("UPDATE branches SET isExpanded = 1 WHERE branchId = 'root'"); - if (this.unrecoveredConsistencyErrors) { + if (!this.unrecoveredConsistencyErrors) { // we run this only if basic checks passed since this assumes basic data consistency this.checkTreeCycles(); diff --git a/src/services/note_revisions.js b/src/services/note_revisions.js index cbf97c16a..d1e7f37b4 100644 --- a/src/services/note_revisions.js +++ b/src/services/note_revisions.js @@ -2,6 +2,7 @@ const NoteRevision = require('../entities/note_revision'); const dateUtils = require('../services/date_utils'); +const log = require('../services/log'); /** * @param {Note} note @@ -9,14 +10,21 @@ const dateUtils = require('../services/date_utils'); function protectNoteRevisions(note) { for (const revision of note.getRevisions()) { if (note.isProtected !== revision.isProtected) { - const content = revision.getContent(); + try { + const content = revision.getContent(); - revision.isProtected = note.isProtected; + revision.isProtected = note.isProtected; - // this will force de/encryption - revision.setContent(content); + // this will force de/encryption + revision.setContent(content); - revision.save(); + revision.save(); + } + catch (e) { + log.error("Could not un/protect note revision ID = " + revision.noteRevisionId); + + throw e; + } } } } diff --git a/src/services/notes.js b/src/services/notes.js index 641af74be..abe6db525 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -185,18 +185,25 @@ function protectNoteRecursively(note, protect, includingSubTree, taskContext) { } function protectNote(note, protect) { - if (protect !== note.isProtected) { - const content = note.getContent(); + try { + if (protect !== note.isProtected) { + const content = note.getContent(); - note.isProtected = protect; + note.isProtected = protect; - // this will force de/encryption - note.setContent(content); + // this will force de/encryption + note.setContent(content); - note.save(); + note.save(); + } + + noteRevisionService.protectNoteRevisions(note); } + catch (e) { + log.error("Could not un/protect note ID = " + note.noteId); - noteRevisionService.protectNoteRevisions(note); + throw e; + } } function findImageLinks(content, foundLinks) {