Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track all errors in Sentry #1558

Merged
merged 5 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public class MXBeaconAggregations: NSObject {

room.redactEvent(relationEvent.eventId, reason: nil) { response in
if case .failure(let error) = response {
MXLog.error("[MXBeaconAggregations] Failed to redact m.beacon event with error: \(error)")
MXLog.error("[MXBeaconAggregations] Failed to redact m.beacon event", context: error)
}
}
}
Expand All @@ -182,7 +182,7 @@ public class MXBeaconAggregations: NSObject {
// Redact stopped beacon info
room.redactEvent(eventId, reason: nil) { response in
if case .failure(let error) = response {
MXLog.error("[MXBeaconAggregations] Failed to redact stopped m.beacon_info event with error: \(error)")
MXLog.error("[MXBeaconAggregations] Failed to redact stopped m.beacon_info event", context: error)
}
}
}
Expand Down Expand Up @@ -258,7 +258,9 @@ public class MXBeaconAggregations: NSObject {
existingBeaconInfoSummary.updateWithBeaconInfo(beaconInfo)
beaconInfoSummary = existingBeaconInfoSummary
} else {
MXLog.error("[MXBeaconAggregations] Fails to find beacon info summary associated to stopped beacon info event id: \(eventId)")
MXLog.error("[MXBeaconAggregations] Fails to find beacon info summary associated to stopped beacon info", context: [
"event_id": eventId
])
}

} else if let existingBeaconInfoSummary = self.getBeaconInfoSummary(withIdentifier: eventId, inRoomWithId: roomId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class MXBeaconInfoSummaryRealmStore: NSObject {
return realm
} catch {

MXLog.error("[MXBeaconInfoSummaryRealmStore] failed to create Realm store with error: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] failed to create Realm store", context: error)
return nil
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public class MXBeaconInfoSummaryRealmStore: NSObject {
do {
try FileManager.default.createDirectory(at: realmFileFolderURL, withIntermediateDirectories: true, attributes: nil)
} catch {
MXLog.error("[MXBeaconInfoSummaryRealmStore] Fail to create Realm folder \(realmFileFolderURL) with error: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] Fail to create Realm folder", context: error)
throw error
}

Expand Down Expand Up @@ -182,7 +182,7 @@ extension MXBeaconInfoSummaryRealmStore: MXBeaconInfoSummaryStoreProtocol {
realm.addOrUpdate(realmBeaconInfoSummary)
}
} catch {
MXLog.error("[MXBeaconInfoSummaryRealmStore] addOrUpdateBeaconInfoSummary failed with error: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] addOrUpdateBeaconInfoSummary failed", context: error)
}
}

Expand Down Expand Up @@ -289,7 +289,7 @@ extension MXBeaconInfoSummaryRealmStore: MXBeaconInfoSummaryStoreProtocol {
realm.deleteObjects(realmBeaconInfoSummaries)
}
} catch {
MXLog.error("[MXBeaconInfoSummaryRealmStore] deleteAllBeaconInfoSummaries failed with error: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] deleteAllBeaconInfoSummaries failed", context: error)
}
}

Expand All @@ -305,7 +305,7 @@ extension MXBeaconInfoSummaryRealmStore: MXBeaconInfoSummaryStoreProtocol {
realm.deleteObjects(realmBeaconInfoSummaries)
}
} catch {
MXLog.error("[MXBeaconInfoSummaryRealmStore] deleteAllBeaconInfoSummaries failed with error: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] deleteAllBeaconInfoSummaries failed", context: error)
}
}

Expand All @@ -320,7 +320,7 @@ extension MXBeaconInfoSummaryRealmStore: MXBeaconInfoSummaryStoreProtocol {
realm.deleteAllObjects()
}
} catch {
MXLog.error("[MXBeaconInfoSummaryRealmStore] Failed to delete all objects: \(error)")
MXLog.error("[MXBeaconInfoSummaryRealmStore] Failed to delete all objects", context: error)
}
}
}
4 changes: 3 additions & 1 deletion MatrixSDK/Aggregations/MXAggregatedReactionsUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ - (MXHTTPOperation*)sendReaction:(NSString*)reaction
MXRoom *room = [self.mxSession roomWithRoomId:roomId];
if (!room)
{
MXLogError(@"[MXAggregations] sendReaction Error: Unknown room: %@", roomId);
MXLogErrorDetails(@"[MXAggregations] sendReaction Error: Unknown room", @{
@"room_id": roomId ?: @"unknown"
});
return nil;
}

Expand Down
5 changes: 4 additions & 1 deletion MatrixSDK/Background/MXBackgroundSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ public enum MXBackgroundSyncServiceError: Error {
case .success:
MXLog.debug("[MXBackgroundSyncService] handleSyncResponse: Joined room: \(roomId)")
case .failure(let error):
MXLog.error("[MXBackgroundSyncService] handleSyncResponse: Failed to join room: \(roomId), error: \(error)")
MXLog.error("[MXBackgroundSyncService] handleSyncResponse: Failed to join room", context: [
"error": error,
"room_id": roomId
])
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK/Crypto/CrossSigning/MXCrossSigningV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MXCrossSigningV2: MXCrossSigning {
success()
}
} catch {
log.error("Cannot setup cross signing", error: error)
log.error("Cannot setup cross signing", context: error)
await MainActor.run {
failure(error)
}
Expand All @@ -92,7 +92,7 @@ class MXCrossSigningV2: MXCrossSigning {
success()
}
} catch {
log.error("Cannot setup cross signing", error: error)
log.error("Cannot setup cross signing", context: error)
await MainActor.run {
failure(error)
}
Expand Down
10 changes: 6 additions & 4 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ extension MXCryptoMachine: MXCryptoDevicesSource {
do {
return try machine.getUserDevices(userId: userId, timeout: 0)
} catch {
log.error("Cannot fetch devices", error: error)
log.error("Cannot fetch devices", context: error)
return []
}
}
Expand All @@ -244,7 +244,7 @@ extension MXCryptoMachine: MXCryptoDevicesSource {
do {
return try machine.getDevice(userId: userId, deviceId: deviceId, timeout: 0)
} catch {
log.error("Cannot fetch device", error: error)
log.error("Cannot fetch device", context: error)
return nil
}
}
Expand All @@ -256,7 +256,7 @@ extension MXCryptoMachine: MXCryptoUserIdentitySource {
do {
return try machine.isIdentityVerified(userId: userId)
} catch {
log.error("Failed checking user verification status", error: error)
log.error("Failed checking user verification status", context: error)
return false
}
}
Expand Down Expand Up @@ -473,7 +473,9 @@ extension MXCryptoMachine: Logger {
}

func log(error: String) {
MXLog.error("[MXCryptoMachine] \(error)")
MXLog.error("[MXCryptoMachine] Error", context: [
"error": error
])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,7 @@ + (void)_deleteStoreWithCredentials:(MXCredentials*)credentials readOnly:(BOOL)r
[RLMRealm deleteFilesForConfiguration:config error:&error];
if (error)
{
MXLogErrorWithDetails(@"[MXRealmCryptoStore] deleteStore error", @{
@"error": error
});
MXLogErrorDetails(@"[MXRealmCryptoStore] deleteStore error", error);

if (!readOnly)
{
Expand All @@ -427,9 +425,7 @@ + (void)_deleteStoreWithCredentials:(MXCredentials*)credentials readOnly:(BOOL)r
}
else
{
MXLogErrorWithDetails(@"[MXRealmCryptoStore] deleteStore: Cannot open realm.", @{
@"error": error
});
MXLogErrorDetails(@"[MXRealmCryptoStore] deleteStore: Cannot open realm.", error);
}
}
}
Expand Down Expand Up @@ -892,7 +888,7 @@ - (void)performSessionOperationWithDevice:(NSString*)deviceKey andSessionId:(NSS
}
else
{
MXLogErrorWithDetails(@"[MXRealmCryptoStore] performSessionOperationWithDevice. Error: olm session not found", @{
MXLogErrorDetails(@"[MXRealmCryptoStore] performSessionOperationWithDevice. Error: olm session not found", @{
@"sessionId": sessionId
});
block(nil);
Expand Down Expand Up @@ -1011,15 +1007,15 @@ - (void)performSessionOperationWithGroupSessionWithId:(NSString*)sessionId sende
}
else
{
MXLogErrorWithDetails(@"[MXRealmCryptoStore] performSessionOperationWithGroupSessionWithId. Error: Cannot build MXOlmInboundGroupSession for megolm session", @{
MXLogErrorDetails(@"[MXRealmCryptoStore] performSessionOperationWithGroupSessionWithId. Error: Cannot build MXOlmInboundGroupSession for megolm session", @{
@"sessionId": sessionId
});
block(nil);
}
}
else
{
MXLogErrorWithDetails(@"[MXRealmCryptoStore] performSessionOperationWithGroupSessionWithId. Error: megolm session not found", @{
MXLogErrorDetails(@"[MXRealmCryptoStore] performSessionOperationWithGroupSessionWithId. Error: megolm session not found", @{
@"sessionId": sessionId
});
block(nil);
Expand Down
20 changes: 15 additions & 5 deletions MatrixSDK/Crypto/Dehydration/MXDehydrationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ - (void)dehydrateDeviceWithMatrixRestClient:(MXRestClient*)restClient

if (error)
{
MXLogError(@"[MXDehydrationService] dehydrateDevice: Account serialization failed: %@", error);
MXLogErrorDetails(@"[MXDehydrationService] dehydrateDevice: Account serialization failed", @{
@"error": error ?: @"unknown"
});
[self stopProgress];
failure(error);
return;
Expand Down Expand Up @@ -114,7 +116,9 @@ - (void)dehydrateDeviceWithMatrixRestClient:(MXRestClient*)restClient
}];
} failure:^(NSError *error) {
[self stopProgress];
MXLogError(@"[MXDehydrationService] dehydrateDevice: Failed pushing dehydrated device data: %@", error);
MXLogErrorDetails(@"[MXDehydrationService] dehydrateDevice: Failed pushing dehydrated device data", @{
@"error": error ?: @"unknown"
});
failure(error);
}];
}
Expand Down Expand Up @@ -176,7 +180,9 @@ - (void)rehydrateDeviceWithMatrixRestClient:(MXRestClient*)restClient
});
}];
} failure:^(NSError *error) {
MXLogError(@"[MXDehydrationService] rehydrateDevice: Claiming dehydrated device failed with error: %@", error);
MXLogErrorDetails(@"[MXDehydrationService] rehydrateDevice: Claiming dehydrated device failed", @{
@"error": error ?: @"unknown"
});
failure(error);
}];
} failure:^(NSError *error) {
Expand All @@ -193,7 +199,9 @@ - (void)rehydrateDeviceWithMatrixRestClient:(MXRestClient*)restClient
}
else
{
MXLogError(@"[MXDehydrationService] rehydrateDevice: DehydratedDeviceId failed with error: %@", error);
MXLogErrorDetails(@"[MXDehydrationService] rehydrateDevice: DehydratedDeviceId failed", @{
@"error": error ?: @"unknown"
});
failure(error);
}
}];
Expand Down Expand Up @@ -229,7 +237,9 @@ - (void)uploadDeviceInfo:(MXDeviceInfo*)deviceInfo
[self stopProgress];
success(deviceInfo.deviceId);
} failure:^(NSError *error) {
MXLogError(@"[MXDehydrationService] uploadDeviceInfo: failed uploading device keys: %@", error);
MXLogErrorDetails(@"[MXDehydrationService] uploadDeviceInfo: failed uploading device keys", @{
@"error": error ?: @"unknown"
});
MXStrongifyAndReturnIfNil(self);
[self stopProgress];
failure(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ + (MXKeyBackupPreparationInfo *)prepareWith:(NSString*)password error:(NSError *

if (*error)
{
MXLogError(@"[MXAes256KeyBackupAlgorithm] prepare: error: %@", *error);
MXLogErrorDetails(@"[MXAes256KeyBackupAlgorithm] prepare", @{
@"error": *error ?: @"unknown"
});
return nil;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ + (MXKeyBackupPreparationInfo *)prepareWith:(NSString *)password error:(NSError

if (*error)
{
MXLogError(@"[MXCurve25519KeyBackupAlgorithm] prepare: error: %@", *error);
MXLogErrorDetails(@"[MXCurve25519KeyBackupAlgorithm] prepare", @{
@"error": *error ?: @"unknown"
});
return nil;
}
return [[MXKeyBackupPreparationInfo alloc] initWithPrivateKey:decryption.privateKey authData:authData];
Expand Down
9 changes: 6 additions & 3 deletions MatrixSDK/Crypto/KeyBackup/MXKeyBackup.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ - (void)checkAndStartWithKeyBackupVersion:(nullable MXKeyBackupVersion*)keyBacku
Class<MXKeyBackupAlgorithm> algorithmClass = AlgorithmClassesByName[keyBackupVersion.algorithm];
if (algorithmClass == NULL)
{
MXLogError(@"[MXKeyBackup] checkAndStartWithKeyBackupVersion: unknown algorithm: %@", keyBackupVersion.algorithm);
NSString *message = [NSString stringWithFormat:@"[MXKeyBackup] checkAndStartWithKeyBackupVersion: unknown algorithm: %@", keyBackupVersion.algorithm];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases the variable is one of very few and it is okay making it a part of the message itself (objc has no StaticString equivalent, so this works)

MXLogError(message);
return;
}
if (![algorithmClass checkBackupVersion:keyBackupVersion])
Expand Down Expand Up @@ -1419,7 +1420,8 @@ - (BOOL)canBeRefreshed
Class<MXKeyBackupAlgorithm> algorithmClass = AlgorithmClassesByName[keyBackupVersion.algorithm];
if (algorithmClass == NULL)
{
MXLogError(@"[MXKeyBackup] getOrCreateKeyBackupAlgorithmFor: unknown algorithm: %@", keyBackupVersion.algorithm);
NSString *message = [NSString stringWithFormat:@"[MXKeyBackup] getOrCreateKeyBackupAlgorithmFor: unknown algorithm: %@", keyBackupVersion.algorithm];
MXLogError(message);
return nil;
}
if (![algorithmClass checkBackupVersion:keyBackupVersion])
Expand Down Expand Up @@ -1553,7 +1555,8 @@ - (nullable NSData*)privateKeyFromCryptoStore
Class<MXKeyBackupAlgorithm> algorithmClass = AlgorithmClassesByName[keyBackupVersion.algorithm];
if (algorithmClass == NULL)
{
MXLogError(@"[MXKeyBackup] megolmBackupAuthDataFromKeyBackupVersion: Key backup for unknown algorithm: %@", keyBackupVersion.algorithm);
NSString *message = [NSString stringWithFormat:@"[MXKeyBackup] megolmBackupAuthDataFromKeyBackupVersion: Key backup for unknown algorithm: %@", keyBackupVersion.algorithm];
MXLogError(message);

*error = [NSError errorWithDomain:MXKeyBackupErrorDomain
code:MXKeyBackupErrorUnknownAlgorithm
Expand Down
Loading