Skip to content

Commit 076b4ee

Browse files
committed
Exposing upload and download errors in SyncStatus.
1 parent 33e6051 commit 076b4ee

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

.changeset/unlucky-flies-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/common': minor
3+
---
4+
5+
Added `downloadError` and `uploadError` members to `SyncDataFlowStatus` of `SyncStatus`.

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ The next upload iteration will be delayed.`);
290290

291291
checkedCrudItem = nextCrudItem;
292292
await this.options.uploadCrud();
293+
this.updateSyncStatus({
294+
dataFlow: {
295+
uploadError: undefined
296+
}
297+
});
293298
} else {
294299
// Uploading is completed
295300
await this.options.adapter.updateLocalTarget(() => this.getWriteCheckpoint());
@@ -299,7 +304,8 @@ The next upload iteration will be delayed.`);
299304
checkedCrudItem = undefined;
300305
this.updateSyncStatus({
301306
dataFlow: {
302-
uploading: false
307+
uploading: false,
308+
uploadError: ex
303309
}
304310
});
305311
await this.delayRetry();
@@ -453,6 +459,12 @@ The next upload iteration will be delayed.`);
453459
this.logger.error(ex);
454460
}
455461

462+
this.updateSyncStatus({
463+
dataFlow: {
464+
downloadError: ex
465+
}
466+
});
467+
456468
// On error, wait a little before retrying
457469
await this.delayRetry();
458470
} finally {
@@ -588,7 +600,8 @@ The next upload iteration will be delayed.`);
588600
connected: true,
589601
lastSyncedAt: new Date(),
590602
dataFlow: {
591-
downloading: false
603+
downloading: false,
604+
downloadError: undefined
592605
}
593606
});
594607
}
@@ -688,7 +701,10 @@ The next upload iteration will be delayed.`);
688701
this.updateSyncStatus({
689702
connected: true,
690703
lastSyncedAt: new Date(),
691-
priorityStatusEntries: []
704+
priorityStatusEntries: [],
705+
dataFlow: {
706+
downloadError: undefined
707+
}
692708
});
693709
} else if (validatedCheckpoint === targetCheckpoint) {
694710
const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint!);
@@ -707,7 +723,8 @@ The next upload iteration will be delayed.`);
707723
lastSyncedAt: new Date(),
708724
priorityStatusEntries: [],
709725
dataFlow: {
710-
downloading: false
726+
downloading: false,
727+
downloadError: undefined
711728
}
712729
});
713730
}

packages/common/src/db/crud/SyncStatus.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
export type SyncDataFlowStatus = Partial<{
22
downloading: boolean;
33
uploading: boolean;
4+
/**
5+
* Error during downloading (including connecting).
6+
*
7+
* Cleared on the next successful data download.
8+
*/
9+
downloadError?: Error;
10+
/**
11+
* Error during uploading.
12+
* Cleared on the next successful upload.
13+
*/
14+
uploadError?: Error;
415
}>;
516

617
export interface SyncPriorityStatus {
@@ -112,7 +123,7 @@ export class SyncStatus {
112123

113124
getMessage() {
114125
const dataFlow = this.dataFlowStatus;
115-
return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}`;
126+
return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}. UploadError: ${dataFlow.uploadError}, DownloadError?: ${dataFlow.downloadError}>`;
116127
}
117128

118129
toJSON(): SyncStatusOptions {

0 commit comments

Comments
 (0)