From f67cbdbc6365ea8edd590b9b701f92bf3d0b2dd6 Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 15 Jan 2024 14:16:31 -0800 Subject: [PATCH] Improve notes sync error handling We no longer persist the sync cursor if the sync encounters an error. This feels safer than the previous approach of always updating the cursor. We also ensure that the "notes sync in progress" is cleared after the sync completes (for both successes and failures). --- src/main.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 599979c..0027649 100644 --- a/src/main.ts +++ b/src/main.ts @@ -110,11 +110,19 @@ export default class InstapaperPlugin extends Plugin { return 0; } - this.log(`Synchronizing notes (${reason})`); this.notesSyncInProgress = true; - const { cursor, count } = await syncNotes(this, token, this.settings.notesCursor); - await this.saveSettings({ notesCursor: cursor }); - this.notesSyncInProgress = false; + this.log(`Synchronizing notes (${reason})`); + let count = 0; + + try { + let cursor; + ({ cursor, count } = await syncNotes(this, token, this.settings.notesCursor)); + await this.saveSettings({ notesCursor: cursor }); + } catch (e) { + this.log('Notes sync failure:', e); + } finally { + this.notesSyncInProgress = false; + } return count; }