From bd00c066c8add45aa5122dcfe87ea34c5714739d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 1 Jun 2020 18:24:41 +0000 Subject: [PATCH] Catch sync errors --- lib/src/client.dart | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index addd9bf..3782939 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -647,6 +647,9 @@ class Client { final StreamController onError = StreamController.broadcast(); + /// Synchronization erros are coming here. + final StreamController onSyncError = StreamController.broadcast(); + /// Synchronization erros are coming here. final StreamController onOlmError = StreamController.broadcast(); @@ -1034,8 +1037,11 @@ class Client { } on MatrixException catch (exception) { onError.add(exception); await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync); - } catch (exception) { - print('Error during processing events: ' + exception.toString()); + } catch (e, s) { + print('Error during processing events: ' + e.toString()); + print(s); + onSyncError.add(SyncError( + exception: e is Exception ? e : Exception(e), stackTrace: s)); await Future.delayed(Duration(seconds: syncErrorTimeoutSec), _sync); } } @@ -1158,7 +1164,7 @@ class Client { print(s); onOlmError.add( ToDeviceEventDecryptionError( - exception: e, + exception: e is Exception ? e : Exception(e), stackTrace: s, toDeviceEvent: toDeviceEvent, ), @@ -2191,3 +2197,9 @@ class Client { return; } } + +class SyncError { + Exception exception; + StackTrace stackTrace; + SyncError({this.exception, this.stackTrace}); +}