refactor: Improve error handling for no olm session found exception
Finding no olm session can happen quiet often when there are dead devices in a room. We do not need to print the whole stacktrace then.
This commit is contained in:
parent
79378714b9
commit
67fd9cd00e
|
|
@ -566,6 +566,10 @@ class OlmManager {
|
||||||
if (fingerprintKey == null ||
|
if (fingerprintKey == null ||
|
||||||
identityKey == null ||
|
identityKey == null ||
|
||||||
!deviceKey.checkJsonSignature(fingerprintKey, userId, deviceId)) {
|
!deviceKey.checkJsonSignature(fingerprintKey, userId, deviceId)) {
|
||||||
|
Logs().w(
|
||||||
|
'Skipping invalid device key from $userId:$deviceId',
|
||||||
|
deviceKey,
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Logs().v('[OlmManager] Starting session with $userId:$deviceId');
|
Logs().v('[OlmManager] Starting session with $userId:$deviceId');
|
||||||
|
|
@ -591,13 +595,17 @@ class OlmManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Encryptes a ToDeviceMessage for the given device with an existing
|
||||||
|
/// olm session.
|
||||||
|
/// Throws `NoOlmSessionFoundException` if there is no olm session with this
|
||||||
|
/// device and none could be created.
|
||||||
Future<Map<String, dynamic>> encryptToDeviceMessagePayload(
|
Future<Map<String, dynamic>> encryptToDeviceMessagePayload(
|
||||||
DeviceKeys device, String type, Map<String, dynamic> payload,
|
DeviceKeys device, String type, Map<String, dynamic> payload,
|
||||||
{bool getFromDb = true}) async {
|
{bool getFromDb = true}) async {
|
||||||
final sess =
|
final sess =
|
||||||
await getOlmSessions(device.curve25519Key!, getFromDb: getFromDb);
|
await getOlmSessions(device.curve25519Key!, getFromDb: getFromDb);
|
||||||
if (sess.isEmpty) {
|
if (sess.isEmpty) {
|
||||||
throw ('No olm session found for ${device.userId}:${device.deviceId}');
|
throw NoOlmSessionFoundException(device);
|
||||||
}
|
}
|
||||||
final fullPayload = {
|
final fullPayload = {
|
||||||
'type': type,
|
'type': type,
|
||||||
|
|
@ -653,8 +661,11 @@ class OlmManager {
|
||||||
userData[device.deviceId!] = await encryptToDeviceMessagePayload(
|
userData[device.deviceId!] = await encryptToDeviceMessagePayload(
|
||||||
device, type, payload,
|
device, type, payload,
|
||||||
getFromDb: false);
|
getFromDb: false);
|
||||||
|
} on NoOlmSessionFoundException catch (e) {
|
||||||
|
Logs().d('[LibOlm] Error encrypting to-device event', e);
|
||||||
|
continue;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().w('[LibOlm] Error encrypting to-device event', e, s);
|
Logs().wtf('[LibOlm] Error encrypting to-device event', e, s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -706,3 +717,13 @@ class OlmManager {
|
||||||
_olmAccount = null;
|
_olmAccount = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NoOlmSessionFoundException implements Exception {
|
||||||
|
final DeviceKeys device;
|
||||||
|
|
||||||
|
NoOlmSessionFoundException(this.device);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() =>
|
||||||
|
'No olm session found for ${device.userId}:${device.deviceId}';
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue