Skip to content

Commit

Permalink
store: Show error message when replacing event queue
Browse files Browse the repository at this point in the history
Fixes: #555

Signed-off-by: Zixuan James Li <[email protected]>
  • Loading branch information
PIG208 committed Sep 12, 2024
1 parent db9d9f1 commit 9cd37ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@
"error": {"type": "String", "example": "Invalid format"}
}
},
"errorReconnectingToServer": "Reconnecting to {serverUrl}…",
"@errorReconnectingToServer": {
"serverUrl": {"type": "String", "example": "http://example.com/"},
"description": "Message when reconnecting to the server."
},
"errorSharingFailed": "Sharing failed",
"@errorSharingFailed": {
"description": "Error message when sharing a message failed."
Expand Down
1 change: 1 addition & 0 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ class UpdateMachine {
switch (e) {
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
assert(debugLog('Lost event queue for $store. Replacing…'));
reportErrorToUserBriefly(localizations.errorReconnectingToServer(serverUrl));
await store._globalStore._reloadPerAccount(store.accountId);
dispose();
debugLog('… Event queue replaced.');
Expand Down
6 changes: 6 additions & 0 deletions test/model/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ void main() {
}

test('handles expired queue', () => awaitFakeAsync((async) async {
reportErrorToUserBriefly = logAndReportErrorToUserBriefly;
addTearDown(() => reportErrorToUserBriefly = defaultReportErrorToUserBriefly);

await prepareStore();
updateMachine.debugPauseLoop();
updateMachine.poll();
Expand All @@ -420,7 +423,10 @@ void main() {
});
updateMachine.debugAdvanceLoop();
async.flushMicrotasks();
check(lastReportedError).isNull();
await Future<void>.delayed(Duration.zero);
check(takeLastReportedError()).isNotNull()
.contains('Reconnecting to ${eg.realmUrl.origin}…');
check(store).isLoading.isTrue();

// The global store has a new store.
Expand Down

0 comments on commit 9cd37ea

Please sign in to comment.