diff --git a/lib/src/client.dart b/lib/src/client.dart index d8a0b7f..a0751a3 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -639,6 +639,10 @@ class Client { final StreamController onError = StreamController.broadcast(); + /// Synchronization erros are coming here. + final StreamController onOlmError = + StreamController.broadcast(); + /// This is called once, when the first sync has received. final StreamController onFirstSync = StreamController.broadcast(); @@ -1134,11 +1138,18 @@ class Client { if (toDeviceEvent.type == 'm.room.encrypted') { try { toDeviceEvent = decryptToDeviceEvent(toDeviceEvent); - } catch (e) { + } catch (e, s) { print( - '[LibOlm] Could not decrypt to device event from ${toDeviceEvent.sender}: ' + - e.toString()); - print(toDeviceEvent.sender); + '[LibOlm] Could not decrypt to device event from ${toDeviceEvent.sender} with content: ${toDeviceEvent.content}'); + print(e); + print(s); + onOlmError.add( + ToDeviceEventDecryptionError( + exception: e, + stackTrace: s, + toDeviceEvent: toDeviceEvent, + ), + ); toDeviceEvent = ToDeviceEvent.fromJson(events[i]); } } diff --git a/lib/src/utils/to_device_event.dart b/lib/src/utils/to_device_event.dart index 11d0fa2..3b7f59d 100644 --- a/lib/src/utils/to_device_event.dart +++ b/lib/src/utils/to_device_event.dart @@ -24,3 +24,17 @@ class ToDeviceEvent { return data; } } + +class ToDeviceEventDecryptionError extends ToDeviceEvent { + Exception exception; + StackTrace stackTrace; + ToDeviceEventDecryptionError({ + ToDeviceEvent toDeviceEvent, + this.exception, + this.stackTrace, + }) : super( + sender: toDeviceEvent.sender, + content: toDeviceEvent.content, + type: toDeviceEvent.type, + ); +}