Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/unlucky-flies-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': minor
---

Added `downloadError` and `uploadError` members to `SyncDataFlowStatus` of `SyncStatus`.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ The next upload iteration will be delayed.`);

checkedCrudItem = nextCrudItem;
await this.options.uploadCrud();
this.updateSyncStatus({
dataFlow: {
uploadError: undefined
}
});
} else {
// Uploading is completed
await this.options.adapter.updateLocalTarget(() => this.getWriteCheckpoint());
Expand All @@ -299,7 +304,8 @@ The next upload iteration will be delayed.`);
checkedCrudItem = undefined;
this.updateSyncStatus({
dataFlow: {
uploading: false
uploading: false,
uploadError: ex
}
});
await this.delayRetry();
Expand Down Expand Up @@ -453,6 +459,12 @@ The next upload iteration will be delayed.`);
this.logger.error(ex);
}

this.updateSyncStatus({
dataFlow: {
downloadError: ex
}
});

// On error, wait a little before retrying
await this.delayRetry();
} finally {
Expand Down Expand Up @@ -588,7 +600,8 @@ The next upload iteration will be delayed.`);
connected: true,
lastSyncedAt: new Date(),
dataFlow: {
downloading: false
downloading: false,
downloadError: undefined
}
});
}
Expand Down Expand Up @@ -688,7 +701,10 @@ The next upload iteration will be delayed.`);
this.updateSyncStatus({
connected: true,
lastSyncedAt: new Date(),
priorityStatusEntries: []
priorityStatusEntries: [],
dataFlow: {
downloadError: undefined
}
});
} else if (validatedCheckpoint === targetCheckpoint) {
const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint!);
Expand All @@ -707,7 +723,8 @@ The next upload iteration will be delayed.`);
lastSyncedAt: new Date(),
priorityStatusEntries: [],
dataFlow: {
downloading: false
downloading: false,
downloadError: undefined
}
});
}
Expand Down
13 changes: 12 additions & 1 deletion packages/common/src/db/crud/SyncStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
export type SyncDataFlowStatus = Partial<{
downloading: boolean;
uploading: boolean;
/**
* Error during downloading (including connecting).
*
* Cleared on the next successful data download.
*/
downloadError?: Error;
/**
* Error during uploading.
* Cleared on the next successful upload.
*/
uploadError?: Error;
}>;

export interface SyncPriorityStatus {
Expand Down Expand Up @@ -112,7 +123,7 @@ export class SyncStatus {

getMessage() {
const dataFlow = this.dataFlowStatus;
return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}`;
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}>`;
}

toJSON(): SyncStatusOptions {
Expand Down