Skip to content

Commit 7e6ab86

Browse files
fix: reset isProcessing when exception is thrown during sync process. (#81)
* Reset ability to sync after exception is possibly thrown in syncing_service.dart * Added `catch` statemet syncing_service.dart. * Fix typo.
1 parent c33abf6 commit 7e6ab86

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

packages/powersync_attachments_helper/lib/src/syncing_service.dart

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,35 @@ class SyncingService {
107107

108108
/// Handle downloading, uploading or deleting of attachments
109109
Future<void> handleSync(Iterable<Attachment> attachments) async {
110-
if (isProcessing == true) {
111-
return;
112-
}
113-
114-
isProcessing = true;
115-
116-
for (Attachment attachment in attachments) {
117-
if (AttachmentState.queuedDownload.index == attachment.state) {
118-
log.info('Downloading ${attachment.filename}');
119-
await downloadAttachment(attachment);
120-
}
121-
if (AttachmentState.queuedUpload.index == attachment.state) {
122-
log.info('Uploading ${attachment.filename}');
123-
await uploadAttachment(attachment);
110+
if (isProcessing == true) {
111+
return;
124112
}
125-
if (AttachmentState.queuedDelete.index == attachment.state) {
126-
log.info('Deleting ${attachment.filename}');
127-
await deleteAttachment(attachment);
113+
114+
try {
115+
isProcessing = true;
116+
117+
for (Attachment attachment in attachments) {
118+
if (AttachmentState.queuedDownload.index == attachment.state) {
119+
log.info('Downloading ${attachment.filename}');
120+
await downloadAttachment(attachment);
121+
}
122+
if (AttachmentState.queuedUpload.index == attachment.state) {
123+
log.info('Uploading ${attachment.filename}');
124+
await uploadAttachment(attachment);
125+
}
126+
if (AttachmentState.queuedDelete.index == attachment.state) {
127+
log.info('Deleting ${attachment.filename}');
128+
await deleteAttachment(attachment);
129+
}
128130
}
131+
} catch (error) {
132+
log.severe(error);
133+
rethrow;
134+
} finally {
135+
// if anything throws an exception
136+
// reset the ability to sync again
137+
isProcessing = false;
129138
}
130-
131-
isProcessing = false;
132139
}
133140

134141
/// Watcher for changes to attachments table

0 commit comments

Comments
 (0)