diff --git a/src/main.ts b/src/main.ts index e13dd68..bb43fb3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -152,9 +152,19 @@ export default class GitHubSyncPlugin extends Plugin { return; } if (this.settings.firstSync) { - await this.syncManager.firstSync(); - this.settings.firstSync = false; - this.saveSettings(); + const notice = new Notice("Syncing..."); + try { + await this.syncManager.firstSync(); + this.settings.firstSync = false; + this.saveSettings(); + // Shown only if sync doesn't fail + new Notice("Sync successful", 5000); + } catch (err) { + // Show the error to the user, it's not automatically dismissed to make sure + // the user sees it. + new Notice(`Error syncing. ${err}`); + } + notice.hide(); } else { await this.syncManager.sync(); } diff --git a/src/sync-manager.ts b/src/sync-manager.ts index ffef47b..1fb1786 100644 --- a/src/sync-manager.ts +++ b/src/sync-manager.ts @@ -95,19 +95,14 @@ export default class SyncManager { return; } - const notice = new Notice("Syncing..."); this.syncing = true; try { await this.firstSyncImpl(); - // Shown only if sync doesn't fail - new Notice("Sync successful", 5000); } catch (err) { - // Show the error to the user, it's not automatically dismissed to make sure - // the user sees it. - new Notice(`Error syncing. ${err}`); + this.syncing = false; + throw err; } this.syncing = false; - notice.hide(); } private async firstSyncImpl() {