Skip to content

Commit c9310c6

Browse files
committed
[green] reread preserved recovery state after unsafe storage failures
Signed-off-by: Viwat Vchirawongkwin <viwat.v@chula.ac.th>
1 parent 90dceec commit c9310c6

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎app/lib/editor/draft_recovery.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ class DraftRecoveryController extends Notifier<DraftRecoveryState> {
335335
failure: _failure(error),
336336
);
337337
}
338+
_stopOnUnsafeFailure(error);
338339
return false;
339340
} finally {
340341
_replacement = false;
@@ -461,6 +462,7 @@ class DraftRecoveryController extends Notifier<DraftRecoveryState> {
461462
hasResolvedStartup: true,
462463
);
463464
}
465+
_stopOnUnsafeFailure(error);
464466
checkpoint.completion.complete(false);
465467
}
466468
}
@@ -541,6 +543,7 @@ class DraftRecoveryController extends Notifier<DraftRecoveryState> {
541543
hasResolvedStartup: true,
542544
);
543545
}
546+
_stopOnUnsafeFailure(error);
544547
return false;
545548
} finally {
546549
_replacement = false;
@@ -576,6 +579,19 @@ class DraftRecoveryController extends Notifier<DraftRecoveryState> {
576579
_maximum = null;
577580
}
578581

582+
void _stopOnUnsafeFailure(Object error) {
583+
final reason = _failure(error);
584+
if (reason == DraftStorageFailure.conflict ||
585+
reason == DraftStorageFailure.corrupt ||
586+
reason == DraftStorageFailure.unsupportedVersion) {
587+
// The high-water mark/content can no longer be trusted. Retry must read
588+
// and offer an explicit choice rather than reusing a stale generation.
589+
_writable = false;
590+
_cancelTimers();
591+
_cancelQueued();
592+
}
593+
}
594+
579595
DraftStorageFailure _failure(Object error) => error is DraftStorageException
580596
? error.reason
581597
: DraftStorageFailure.unavailable;

0 commit comments

Comments
 (0)