Skip to content

Commit

Permalink
Do not track cancellation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Anderas committed Dec 15, 2022
1 parent 4ec84cf commit e17a743
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
14 changes: 14 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,8 @@
ED6DAC1F28C79D2000ECDCB6 /* MXUnrequestedForwardedRoomKeyManagerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6DAC1D28C79D2000ECDCB6 /* MXUnrequestedForwardedRoomKeyManagerUnitTests.swift */; };
ED6DAC2128C7A51400ECDCB6 /* MXDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6DAC2028C7A4F000ECDCB6 /* MXDateProvider.swift */; };
ED6DAC2228C7A51400ECDCB6 /* MXDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6DAC2028C7A4F000ECDCB6 /* MXDateProvider.swift */; };
ED6E87A9294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6E87A8294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift */; };
ED6E87AA294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED6E87A8294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift */; };
ED7019DD2886C24100FC31B9 /* MXCrossSigningInfoSourceUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D242885A39800F897E7 /* MXCrossSigningInfoSourceUnitTests.swift */; };
ED7019DE2886C24A00FC31B9 /* MXTrustLevelSourceUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D2F2885AB0300F897E7 /* MXTrustLevelSourceUnitTests.swift */; };
ED7019DF2886C25600FC31B9 /* MXDeviceInfoUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED8F1D1B2885909E00F897E7 /* MXDeviceInfoUnitTests.swift */; };
Expand Down Expand Up @@ -3077,6 +3079,7 @@
ED6DAC1A28C79AA300ECDCB6 /* MXUnrequestedForwardedRoomKeyManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXUnrequestedForwardedRoomKeyManager.swift; sourceTree = "<group>"; };
ED6DAC1D28C79D2000ECDCB6 /* MXUnrequestedForwardedRoomKeyManagerUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXUnrequestedForwardedRoomKeyManagerUnitTests.swift; sourceTree = "<group>"; };
ED6DAC2028C7A4F000ECDCB6 /* MXDateProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXDateProvider.swift; sourceTree = "<group>"; };
ED6E87A8294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXAnalyticsDestinationUnitTests.swift; sourceTree = "<group>"; };
ED7019E42886C32900FC31B9 /* MXSASTransactionV2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXSASTransactionV2.swift; sourceTree = "<group>"; };
ED7019E72886C33100FC31B9 /* MXKeyVerificationRequestV2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXKeyVerificationRequestV2.swift; sourceTree = "<group>"; };
ED7019EA2886C33A00FC31B9 /* MXKeyVerificationManagerV2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXKeyVerificationManagerV2.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3434,6 +3437,7 @@
322985C526FA66FD001890BC /* Utils */ = {
isa = PBXGroup;
children = (
ED6E87A7294B3B9900100D9C /* Logs */,
322985CA26FAF898001890BC /* MXSession.swift */,
322985CE26FBAE7B001890BC /* TestObserver.swift */,
322985D126FC9E61001890BC /* MXSessionTracker.swift */,
Expand Down Expand Up @@ -5508,6 +5512,14 @@
path = Store;
sourceTree = "<group>";
};
ED6E87A7294B3B9900100D9C /* Logs */ = {
isa = PBXGroup;
children = (
ED6E87A8294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift */,
);
path = Logs;
sourceTree = "<group>";
};
ED7019ED2886CA6C00FC31B9 /* Verification */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -7238,6 +7250,7 @@
B146D4FF21A5C0BD00D8C2C6 /* MXMediaScanStoreUnitTests.m in Sources */,
32BD34BE1E84134A006EDC0D /* MatrixSDKTestsE2EData.m in Sources */,
ED751DAE28EDEC7E003748C3 /* MXKeyVerificationStateResolverUnitTests.swift in Sources */,
ED6E87A9294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift in Sources */,
B146D4FE21A5C0BD00D8C2C6 /* MXEventScanStoreUnitTests.m in Sources */,
EDF1B6932876CD8600BBBCEE /* MXTaskQueueUnitTests.swift in Sources */,
32684CB821085F770046D2F9 /* MXLazyLoadingTests.m in Sources */,
Expand Down Expand Up @@ -7885,6 +7898,7 @@
B1E09A242397FCE90057C069 /* MXPeekingRoomTests.m in Sources */,
B1E09A452397FD990057C069 /* MXLazyLoadingTests.m in Sources */,
ED751DAF28EDEC7E003748C3 /* MXKeyVerificationStateResolverUnitTests.swift in Sources */,
ED6E87AA294B3BAB00100D9C /* MXAnalyticsDestinationUnitTests.swift in Sources */,
B1E09A1C2397FCE90057C069 /* MXEventAnnotationUnitTests.swift in Sources */,
B1E09A262397FCE90057C069 /* MXPushRuleUnitTests.m in Sources */,
EDF1B6942876CD8600BBBCEE /* MXTaskQueueUnitTests.swift in Sources */,
Expand Down
20 changes: 17 additions & 3 deletions MatrixSDK/Utils/Logs/MXAnalyticsDestination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ class MXAnalyticsDestination: BaseDestination {

override func send(_ level: SwiftyBeaver.Level, msg: String, thread: String, file: String, function: String, line: Int, context: Any? = nil) -> String? {
let message = super.send(level, msg: msg, thread: thread, file: file, function: function, line: line, context: context)
#if !DEBUG
MXSDKOptions.sharedInstance().analyticsDelegate?.trackNonFatalIssue(msg, details: formattedDetails(from: context))
#endif
if shouldTrackIssue(with: context) {
MXSDKOptions.sharedInstance().analyticsDelegate?.trackNonFatalIssue(msg, details: formattedDetails(from: context))
}
return message
}

private func shouldTrackIssue(with context: Any?) -> Bool {
// We will track all issues except for those with a cancellation error
guard let error = context as? NSError else {
return true
}
return !error.isCancelledError
}

private func formattedDetails(from context: Any?) -> [String: Any]? {
guard let context = context else {
return nil
Expand All @@ -54,3 +62,9 @@ class MXAnalyticsDestination: BaseDestination {
}
}
}

private extension NSError {
var isCancelledError: Bool {
domain == NSURLErrorDomain && code == NSURLErrorCancelled
}
}
3 changes: 3 additions & 0 deletions MatrixSDK/Utils/Logs/MXLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ private var logger: SwiftyBeaver.Type = {
}
logger.addDestination(consoleDestination)

#if !DEBUG
// Non-debug builds will log fatal issues to analytics if tracking consent provided
let analytics = MXAnalyticsDestination()
logger.addDestination(analytics)
#endif
}
}

Expand Down
1 change: 1 addition & 0 deletions MatrixSDKTests/TestPlans/UnitTests.xctestplan
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"MXAesUnitTests",
"MXAggregatedEditsUnitTests",
"MXAggregatedReferenceUnitTests",
"MXAnalyticsDestinationUnitTests",
"MXAsyncTaskQueueUnitTests",
"MXAuthenticationSessionUnitTests",
"MXBackgroundTaskUnitTests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"MXAesUnitTests",
"MXAggregatedEditsUnitTests",
"MXAggregatedReferenceUnitTests",
"MXAnalyticsDestinationUnitTests",
"MXAsyncTaskQueueUnitTests",
"MXAuthenticationSessionUnitTests",
"MXBackgroundTaskUnitTests",
Expand Down

0 comments on commit e17a743

Please sign in to comment.