From 9771e480492d1d86d13d6e1950a0e2b3983b344a Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 21 May 2025 02:39:49 +0530 Subject: [PATCH] fix(mobile): do not continue on remote stream parse error (#18344) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- .../repositories/sync_api.repository.dart | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/mobile/lib/infrastructure/repositories/sync_api.repository.dart b/mobile/lib/infrastructure/repositories/sync_api.repository.dart index dd1ea208ba..c69122335e 100644 --- a/mobile/lib/infrastructure/repositories/sync_api.repository.dart +++ b/mobile/lib/infrastructure/repositories/sync_api.repository.dart @@ -25,7 +25,6 @@ class SyncApiRepository implements ISyncApiRepository { int batchSize = kSyncEventBatchSize, http.Client? httpClient, }) async { - // ignore: avoid-unused-assignment final stopwatch = Stopwatch()..start(); final client = httpClient ?? http.Client(); final endpoint = "${_api.apiClient.basePath}/sync/stream"; @@ -98,7 +97,7 @@ class SyncApiRepository implements ISyncApiRepository { await onData(_parseLines(lines), abort); } } catch (error, stack) { - _logger.severe("error processing stream", error, stack); + _logger.severe("Error processing stream", error, stack); return Future.error(error, stack); } finally { client.close(); @@ -112,21 +111,17 @@ class SyncApiRepository implements ISyncApiRepository { final List data = []; for (final line in lines) { - try { - final jsonData = jsonDecode(line); - final type = SyncEntityType.fromJson(jsonData['type'])!; - final dataJson = jsonData['data']; - final ack = jsonData['ack']; - final converter = _kResponseMap[type]; - if (converter == null) { - _logger.warning("[_parseSyncResponse] Unknown type $type"); - continue; - } - - data.add(SyncEvent(type: type, data: converter(dataJson), ack: ack)); - } catch (error, stack) { - _logger.severe("[_parseSyncResponse] Error parsing json", error, stack); + final jsonData = jsonDecode(line); + final type = SyncEntityType.fromJson(jsonData['type'])!; + final dataJson = jsonData['data']; + final ack = jsonData['ack']; + final converter = _kResponseMap[type]; + if (converter == null) { + _logger.warning("Unknown type $type"); + continue; } + + data.add(SyncEvent(type: type, data: converter(dataJson), ack: ack)); } return data;