Quellcode durchsuchen

Handle incorrect sync status

vishnukvmd vor 4 Jahren
Ursprung
Commit
fad5eb687d
2 geänderte Dateien mit 16 neuen und 1 gelöschten Zeilen
  1. 5 1
      lib/core/errors.dart
  2. 11 0
      lib/services/remote_sync_service.dart

+ 5 - 1
lib/core/errors.dart

@@ -16,4 +16,8 @@ class LockAlreadyAcquiredError extends Error {}
 
 class UnauthorizedError extends Error {}
 
-class RequestCancelledError extends Error{}
+class RequestCancelledError extends Error {}
+
+class InvalidSyncStatusError extends AssertionError {
+  InvalidSyncStatusError(String message) : super(message);
+}

+ 11 - 0
lib/services/remote_sync_service.dart

@@ -161,6 +161,17 @@ class RemoteSyncService {
     if (toBeUploadedInThisSession == 0) {
       return;
     }
+    if (_completedUploads > toBeUploadedInThisSession ||
+        _completedUploads < 0 ||
+        toBeUploadedInThisSession < 0) {
+      _logger.severe(
+          "Incorrect sync status",
+          InvalidSyncStatusError("Tried to report " +
+              _completedUploads.toString() +
+              " as uploaded out of " +
+              toBeUploadedInThisSession.toString()));
+      return;
+    }
     Bus.instance.fire(SyncStatusUpdate(SyncStatus.in_progress,
         completed: _completedUploads, total: toBeUploadedInThisSession));
   }