Skip to content

Commit 71c8c47

Browse files
committed
store: Report non-transient polling errors.
Signed-off-by: Zixuan James Li <[email protected]>
1 parent 512aa1b commit 71c8c47

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

assets/l10n/app_en.arb

+7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@
160160
"message": {"type": "String", "example": "Invalid format"}
161161
}
162162
},
163+
"errorLoadingServerData": "Error loading server data. Will retry:\n\n{error}",
164+
"@errorLoadingServerData": {
165+
"description": "Dialog message for a generic unknown error.",
166+
"placeholders": {
167+
"error": {"type": "String", "example": "Invalid format"}
168+
}
169+
},
163170
"errorSharingFailed": "Sharing failed",
164171
"@errorSharingFailed": {
165172
"description": "Error message when sharing a message failed."

lib/model/store.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import '../log.dart';
2020
import '../notifications/receive.dart';
2121
import 'autocomplete.dart';
2222
import 'database.dart';
23+
import 'localizations.dart';
2324
import 'message.dart';
2425
import 'message_list.dart';
2526
import 'recent_dm_conversations.dart';
@@ -782,6 +783,7 @@ class UpdateMachine {
782783
queueId: queueId, lastEventId: lastEventId);
783784
} catch (e) {
784785
store.isLoading = true;
786+
final localizations = GlobalLocalizations.zulipLocalizations;
785787
switch (e) {
786788
case ZulipApiException(code: 'BAD_EVENT_QUEUE_ID'):
787789
assert(debugLog('Lost event queue for $store. Replacing…'));
@@ -802,7 +804,9 @@ class UpdateMachine {
802804
default:
803805
assert(debugLog('Error polling event queue for $store: $e\n'
804806
'Backing off and retrying even though may be hopeless…'));
805-
// TODO tell user on non-transient error in polling
807+
// TODO(#186): Handle unrecoverable failures
808+
reportErrorToUserInDialog(
809+
localizations.errorLoadingServerData(e.toString()));
806810
await (backoffMachine ??= BackoffMachine()).wait();
807811
assert(debugLog('… Backoff wait complete, retrying poll.'));
808812
continue;

test/model/store_test.dart

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:zulip/api/model/events.dart';
88
import 'package:zulip/api/model/model.dart';
99
import 'package:zulip/api/route/events.dart';
1010
import 'package:zulip/api/route/messages.dart';
11+
import 'package:zulip/log.dart';
1112
import 'package:zulip/model/store.dart';
1213
import 'package:zulip/notifications/receive.dart';
1314

@@ -427,7 +428,9 @@ void main() {
427428
check(store.userSettings!.twentyFourHourTime).isTrue();
428429
}));
429430

430-
void checkRetry(String description, void Function() prepareError) {
431+
void checkRetry(String description, void Function() prepareError, {
432+
String? errorMessage,
433+
}) {
431434
test(description, () {
432435
awaitFakeAsync((async) async {
433436
await prepareStore(lastEventId: 1);
@@ -438,7 +441,13 @@ void main() {
438441
// Make the request, inducing an error in it.
439442
prepareError();
440443
updateMachine.debugAdvanceLoop();
444+
check(debugLastReportedError).isNull();
441445
async.elapse(Duration.zero);
446+
if (errorMessage == null) {
447+
check(takeLastReportedError()).isNull();
448+
} else {
449+
check(takeLastReportedError()).isNotNull().contains(errorMessage);
450+
}
442451
checkLastRequest(lastEventId: 1);
443452
check(store).isLoading.isTrue();
444453

@@ -470,10 +479,12 @@ void main() {
470479

471480
checkRetry('retries on ZulipApiException',
472481
() => connection.prepare(httpStatus: 400, json: {
473-
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}));
482+
'result': 'error', 'code': 'BAD_REQUEST', 'msg': 'Bad request'}),
483+
errorMessage: 'Error loading server data. Will retry');
474484

475485
checkRetry('retries on MalformedServerResponseException',
476-
() => connection.prepare(httpStatus: 200, body: 'nonsense'));
486+
() => connection.prepare(httpStatus: 200, body: 'nonsense'),
487+
errorMessage: 'Error loading server data. Will retry');
477488
});
478489
});
479490

0 commit comments

Comments
 (0)