diff --git a/Samples/Common/Sources/IntegrationTestsHelper/ReportConfig.swift b/Samples/Common/Sources/IntegrationTestsHelper/ReportConfig.swift index 0cb20044..2fd4fcaa 100644 --- a/Samples/Common/Sources/IntegrationTestsHelper/ReportConfig.swift +++ b/Samples/Common/Sources/IntegrationTestsHelper/ReportConfig.swift @@ -61,7 +61,7 @@ public class DirectorySink: NSObject, CrashReportFilter { self.directoryUrl = directoryUrl } - public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, Bool, (any Error)?) -> Void)? = nil) { + public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, (any Error)?) -> Void)? = nil) { let prefix = UUID().uuidString for (idx, report) in reports.enumerated() { let fileName = "\(prefix)-\(idx).ips" @@ -82,6 +82,6 @@ public class DirectorySink: NSObject, CrashReportFilter { Self.logger.error("Failed to save report: \(error)") } } - onCompletion?(reports, true, nil) + onCompletion?(reports, nil) } } diff --git a/Samples/Common/Sources/LibraryBridge/CrashReportStore+Bridge.swift b/Samples/Common/Sources/LibraryBridge/CrashReportStore+Bridge.swift index a2c5ebb6..d600fe95 100644 --- a/Samples/Common/Sources/LibraryBridge/CrashReportStore+Bridge.swift +++ b/Samples/Common/Sources/LibraryBridge/CrashReportStore+Bridge.swift @@ -35,10 +35,7 @@ public extension CrashReportStore { private static let logger = Logger(label: "ReportingSample") func logAll() async throws { - let (reports, isSuccess) = try await sendAllReports() - guard isSuccess else { - return - } + let reports = try await sendAllReports() for report in reports { guard let report = report as? CrashReportDictionary else { continue @@ -49,8 +46,8 @@ public extension CrashReportStore { func logToConsole() { sink = CrashReportSinkConsole.filter().defaultCrashReportFilterSet() - sendAllReports { reports, isSuccess, error in - if isSuccess, let reports { + sendAllReports { reports, error in + if let reports { Self.logger.info("Logged \(reports.count) reports") for (idx, report) in reports.enumerated() { switch report { @@ -70,6 +67,15 @@ public extension CrashReportStore { } } + func logWithAlert() { + sink = CrashReportFilterPipeline(filtersArray: [ + CrashReportFilterAlert(title: "Sample Alert", message: "Do you want to log?", yesAnswer: "Yes", noAnswer: "No"), + CrashReportFilterAppleFmt(), + CrashReportSinkConsole(), + ]) + sendAllReports() + } + func sampleLogToConsole() { sink = CrashReportFilterPipeline(filtersArray: [ CrashReportFilterDemangle(), @@ -123,21 +129,21 @@ public class SampleCrashReport: NSObject, CrashReport { } public class SampleFilter: NSObject, CrashReportFilter { - public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, Bool, (any Error)?) -> Void)? = nil) { + public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, (any Error)?) -> Void)? = nil) { let filtered = reports.compactMap { report -> SampleCrashReport? in guard let dictReport = report as? CrashReportDictionary else { return nil } return SampleCrashReport(dictReport) } - onCompletion?(filtered, true, nil) + onCompletion?(filtered, nil) } } public class SampleSink: NSObject, CrashReportFilter { private static let logger = Logger(label: "SampleSink") - public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, Bool, (any Error)?) -> Void)? = nil) { + public func filterReports(_ reports: [any CrashReport], onCompletion: (([any CrashReport]?, (any Error)?) -> Void)? = nil) { for (idx, report) in reports.enumerated() { guard let sampleReport = report as? SampleCrashReport else { continue @@ -149,6 +155,6 @@ public class SampleSink: NSObject, CrashReportFilter { let text = lines.joined(separator: "\n") Self.logger.info("\(text)") } - onCompletion?(reports, true, nil) + onCompletion?(reports, nil) } } diff --git a/Samples/Common/Sources/SampleUI/Screens/ReportingView.swift b/Samples/Common/Sources/SampleUI/Screens/ReportingView.swift index 0af5bbc9..c72749c3 100644 --- a/Samples/Common/Sources/SampleUI/Screens/ReportingView.swift +++ b/Samples/Common/Sources/SampleUI/Screens/ReportingView.swift @@ -39,6 +39,9 @@ struct ReportingView: View { Button("Sample Custom Log To Console") { store.sampleLogToConsole() } + Button("Log with Alert") { + store.logWithAlert() + } } .navigationTitle("Report") } diff --git a/Sources/KSCrashDemangleFilter/KSCrashReportFilterDemangle.m b/Sources/KSCrashDemangleFilter/KSCrashReportFilterDemangle.m index e12870be..66ae03e1 100644 --- a/Sources/KSCrashDemangleFilter/KSCrashReportFilterDemangle.m +++ b/Sources/KSCrashDemangleFilter/KSCrashReportFilterDemangle.m @@ -165,7 +165,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras [filteredReports addObject:[KSCrashReportDictionary reportWithValue:reportDict]]; } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end diff --git a/Sources/KSCrashFilters/KSCrashReportFilterAlert.m b/Sources/KSCrashFilters/KSCrashReportFilterAlert.m index 4f8d497a..df4ec405 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterAlert.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterAlert.m @@ -27,6 +27,7 @@ #import "KSCrashReportFilterAlert.h" #import "KSCrashReport.h" +#import "KSNSErrorHelper.h" #import "KSSystemCapabilities.h" // #define KSLogger_LocalLevel TRACE @@ -82,18 +83,17 @@ - (void)startWithTitle:(NSString *)title UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *yesAction = - [UIAlertAction actionWithTitle:yesAnswer - style:UIAlertActionStyleDefault - handler:^(__unused UIAlertAction *_Nonnull action) { - kscrash_callCompletion(self.onCompletion, self.reports, YES, nil); - }]; - UIAlertAction *noAction = - [UIAlertAction actionWithTitle:noAnswer - style:UIAlertActionStyleCancel - handler:^(__unused UIAlertAction *_Nonnull action) { - kscrash_callCompletion(self.onCompletion, self.reports, NO, nil); - }]; + UIAlertAction *yesAction = [UIAlertAction actionWithTitle:yesAnswer + style:UIAlertActionStyleDefault + handler:^(__unused UIAlertAction *_Nonnull action) { + kscrash_callCompletion(self.onCompletion, self.reports, nil); + }]; + UIAlertAction *noAction = [UIAlertAction + actionWithTitle:noAnswer + style:UIAlertActionStyleCancel + handler:^(__unused UIAlertAction *_Nonnull action) { + kscrash_callCompletion(self.onCompletion, self.reports, [[self class] cancellationError]); + }]; [alertController addAction:yesAction]; [alertController addAction:noAction]; UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; @@ -108,18 +108,24 @@ - (void)startWithTitle:(NSString *)title [alert setInformativeText:message]; [alert setAlertStyle:NSAlertStyleInformational]; - BOOL success = NO; - if ([alert runModal] == NSAlertFirstButtonReturn) { - success = noAnswer != nil; + NSModalResponse response = [alert runModal]; + NSError *error = nil; + if (noAnswer != nil && response == NSAlertSecondButtonReturn) { + error = [[self class] cancellationError]; } - kscrash_callCompletion(self.onCompletion, self.reports, success, nil); + kscrash_callCompletion(self.onCompletion, self.reports, error); #endif } ++ (NSError *)cancellationError +{ + return [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Cancelled by user"]; +} + - (void)alertView:(__unused id)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { BOOL success = buttonIndex == self.expectedButtonIndex; - kscrash_callCompletion(self.onCompletion, self.reports, success, nil); + kscrash_callCompletion(self.onCompletion, self.reports, success ? nil : [[self class] cancellationError]); } @end @@ -167,9 +173,9 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras yesAnswer:self.yesAnswer noAnswer:self.noAnswer reports:reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray *filteredReports, NSError *error) { KSLOG_TRACE(@"alert process complete"); - kscrash_callCompletion(onCompletion, filteredReports, completed, error); + kscrash_callCompletion(onCompletion, filteredReports, error); dispatch_async(dispatch_get_main_queue(), ^{ process = nil; }); @@ -205,7 +211,7 @@ - (id)initWithTitle:(__unused NSString *)title - (void)filterReports:(NSArray> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion { KSLOG_WARN(@"Alert filter not available on this platform."); - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); } @end diff --git a/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m b/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m index c085bd35..2203f21b 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m @@ -210,7 +210,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } - (NSString *)CPUType:(NSString *)CPUArch isSystemInfoHeader:(BOOL)isSystemInfoHeader diff --git a/Sources/KSCrashFilters/KSCrashReportFilterBasic.m b/Sources/KSCrashFilters/KSCrashReportFilterBasic.m index c32c1bea..80d72c93 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterBasic.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterBasic.m @@ -42,7 +42,7 @@ + (instancetype)filter - (void)filterReports:(NSArray> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion { - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); } @end @@ -120,13 +120,13 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSUInteger filterCount = [filters count]; if (filterCount == 0) { - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); return; } if (filterCount != [keys count]) { kscrash_callCompletion( - onCompletion, reports, NO, + onCompletion, reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Key/filter mismatch (%d keys, %d filters", [keys count], filterCount]); @@ -144,12 +144,12 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras filterCompletion = nil; }); } copy]; - filterCompletion = [^(NSArray> *filteredReports, BOOL completed, NSError *filterError) { - if (!completed || filteredReports == nil) { - if (!completed) { - kscrash_callCompletion(onCompletion, filteredReports, completed, filterError); + filterCompletion = [^(NSArray> *filteredReports, NSError *filterError) { + if (filterError != nil || filteredReports == nil) { + if (filterError != nil) { + kscrash_callCompletion(onCompletion, filteredReports, filterError); } else if (filteredReports == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, + kscrash_callCompletion(onCompletion, filteredReports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"filteredReports was nil"]); @@ -184,7 +184,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras [combinedReports addObject:report]; } - kscrash_callCompletion(onCompletion, combinedReports, completed, filterError); + kscrash_callCompletion(onCompletion, combinedReports, filterError); disposeOfCompletion(); } copy]; weakFilterCompletion = filterCompletion; @@ -248,7 +248,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSUInteger filterCount = [filters count]; if (filterCount == 0) { - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); return; } @@ -261,12 +261,12 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras filterCompletion = nil; }); } copy]; - filterCompletion = [^(NSArray> *filteredReports, BOOL completed, NSError *filterError) { - if (!completed || filteredReports == nil) { - if (!completed) { - kscrash_callCompletion(onCompletion, filteredReports, completed, filterError); + filterCompletion = [^(NSArray> *filteredReports, NSError *filterError) { + if (filterError != nil || filteredReports == nil) { + if (filterError != nil) { + kscrash_callCompletion(onCompletion, filteredReports, filterError); } else if (filteredReports == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, + kscrash_callCompletion(onCompletion, filteredReports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"filteredReports was nil"]); @@ -284,7 +284,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras } // All filters complete, or a filter failed. - kscrash_callCompletion(onCompletion, filteredReports, completed, filterError); + kscrash_callCompletion(onCompletion, filteredReports, filterError); disposeOfCompletion(); } copy]; weakFilterCompletion = filterCompletion; @@ -361,7 +361,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras } [filteredReports addObject:concatenated]; } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end @@ -421,7 +421,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras for (NSString *keyPath in self.keyPaths) { id object = [KSNSDictionaryHelper objectInDictionary:report.value forKeyPath:keyPath]; if (object == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, + kscrash_callCompletion(onCompletion, filteredReports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Report did not have key path %@", keyPath]); @@ -432,7 +432,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras id subsetReport = [KSCrashReportDictionary reportWithValue:subset]; [filteredReports addObject:subsetReport]; } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end @@ -461,7 +461,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras [filteredReports addObject:[KSCrashReportString reportWithValue:converted]]; } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end @@ -484,7 +484,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSData *converted = [report.value dataUsingEncoding:NSUTF8StringEncoding]; if (converted == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, + kscrash_callCompletion(onCompletion, filteredReports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Could not convert report to UTF-8"]); @@ -494,7 +494,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end diff --git a/Sources/KSCrashFilters/KSCrashReportFilterGZip.m b/Sources/KSCrashFilters/KSCrashReportFilterGZip.m index 9318d0c1..60563c8f 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterGZip.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterGZip.m @@ -66,14 +66,14 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras compressionLevel:(int)self.compressionLevel error:&error]; if (compressedData == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, error); + kscrash_callCompletion(onCompletion, filteredReports, error); return; } else { [filteredReports addObject:[KSCrashReportData reportWithValue:compressedData]]; } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end @@ -97,14 +97,14 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSError *error = nil; NSData *decompressedData = [KSGZipHelper gunzippedData:report.value error:&error]; if (decompressedData == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, error); + kscrash_callCompletion(onCompletion, filteredReports, error); return; } else { [filteredReports addObject:[KSCrashReportData reportWithValue:decompressedData]]; } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end diff --git a/Sources/KSCrashFilters/KSCrashReportFilterJSON.m b/Sources/KSCrashFilters/KSCrashReportFilterJSON.m index d40683e7..e0ab9439 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterJSON.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterJSON.m @@ -63,14 +63,14 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSError *error = nil; NSData *jsonData = [KSJSONCodec encode:report.value options:self.encodeOptions error:&error]; if (jsonData == nil) { - kscrash_callCompletion(onCompletion, filteredReports, NO, error); + kscrash_callCompletion(onCompletion, filteredReports, error); return; } else { [filteredReports addObject:[KSCrashReportData reportWithValue:jsonData]]; } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end @@ -108,14 +108,14 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras NSError *error = nil; NSDictionary *decodedReport = [KSJSONCodec decode:report.value options:self.decodeOptions error:&error]; if (decodedReport == nil || [decodedReport isKindOfClass:[NSDictionary class]] == NO) { - kscrash_callCompletion(onCompletion, filteredReports, NO, error); + kscrash_callCompletion(onCompletion, filteredReports, error); return; } else { [filteredReports addObject:[KSCrashReportDictionary reportWithValue:decodedReport]]; } } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end diff --git a/Sources/KSCrashFilters/KSCrashReportFilterStringify.m b/Sources/KSCrashFilters/KSCrashReportFilterStringify.m index c91d8933..7797a193 100644 --- a/Sources/KSCrashFilters/KSCrashReportFilterStringify.m +++ b/Sources/KSCrashFilters/KSCrashReportFilterStringify.m @@ -64,7 +64,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras [filteredReports addObject:[KSCrashReportString reportWithValue:reportString]]; } - kscrash_callCompletion(onCompletion, filteredReports, YES, nil); + kscrash_callCompletion(onCompletion, filteredReports, nil); } @end diff --git a/Sources/KSCrashInstallations/KSCrashInstallation.m b/Sources/KSCrashInstallations/KSCrashInstallation.m index 21fd0bb4..f5c190ea 100644 --- a/Sources/KSCrashInstallations/KSCrashInstallation.m +++ b/Sources/KSCrashInstallations/KSCrashInstallation.m @@ -299,14 +299,14 @@ - (void)sendAllReportsWithCompletion:(KSCrashReportFilterCompletion)onCompletion NSError *error = [self validateProperties]; if (error != nil) { if (onCompletion != nil) { - onCompletion(nil, NO, error); + onCompletion(nil, error); } return; } id sink = [self sink]; if (sink == nil) { - onCompletion(nil, NO, + onCompletion(nil, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Sink was nil (subclasses must implement method \"sink\")"]); @@ -325,11 +325,10 @@ - (void)sendAllReportsWithCompletion:(KSCrashReportFilterCompletion)onCompletion KSCrashReportStore *store = [KSCrash sharedInstance].reportStore; if (store == nil) { onCompletion( - nil, NO, - [KSNSErrorHelper - errorWithDomain:[[self class] description] - code:0 - description:@"Reporting is not allowed before the call of `installWithConfiguration:error:`"]); + nil, [KSNSErrorHelper + errorWithDomain:[[self class] description] + code:0 + description:@"Reporting is not allowed before the call of `installWithConfiguration:error:`"]); return; } diff --git a/Sources/KSCrashRecording/KSCrashReportStore.m b/Sources/KSCrashRecording/KSCrashReportStore.m index 9f878e16..2d3b8fda 100644 --- a/Sources/KSCrashRecording/KSCrashReportStore.m +++ b/Sources/KSCrashRecording/KSCrashReportStore.m @@ -83,16 +83,16 @@ - (void)sendAllReportsWithCompletion:(KSCrashReportFilterCompletion)onCompletion __weak __typeof(self) weakSelf = self; [self sendReports:reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray *filteredReports, NSError *error) { KSLOG_DEBUG(@"Process finished with completion: %d", completed); if (error != nil) { KSLOG_ERROR(@"Failed to send reports: %@", error); } - if ((self.reportCleanupPolicy == KSCrashReportCleanupPolicyOnSuccess && completed) || + if ((self.reportCleanupPolicy == KSCrashReportCleanupPolicyOnSuccess && error == nil) || self.reportCleanupPolicy == KSCrashReportCleanupPolicyAlways) { [weakSelf deleteAllReports]; } - kscrash_callCompletion(onCompletion, filteredReports, completed, error); + kscrash_callCompletion(onCompletion, filteredReports, error); }]; } @@ -116,12 +116,12 @@ - (NSInteger)reportCount - (void)sendReports:(NSArray> *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion { if ([reports count] == 0) { - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); return; } if (self.sink == nil) { - kscrash_callCompletion(onCompletion, reports, NO, + kscrash_callCompletion(onCompletion, reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"No sink set. Crash reports not sent."]); @@ -129,8 +129,8 @@ - (void)sendReports:(NSArray> *)reports onCompletion:(KSCrashR } [self.sink filterReports:reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - kscrash_callCompletion(onCompletion, filteredReports, completed, error); + onCompletion:^(NSArray *filteredReports, NSError *error) { + kscrash_callCompletion(onCompletion, filteredReports, error); }]; } diff --git a/Sources/KSCrashRecording/include/KSCrashReportFilter.h b/Sources/KSCrashRecording/include/KSCrashReportFilter.h index c7a23119..67ddac33 100644 --- a/Sources/KSCrashRecording/include/KSCrashReportFilter.h +++ b/Sources/KSCrashRecording/include/KSCrashReportFilter.h @@ -32,14 +32,10 @@ NS_ASSUME_NONNULL_BEGIN /** Callback for filter operations. * - * @param filteredReports The filtered reports (may be incomplete if "completed" - * is false). - * @param completed True if filtering completed. - * Can be false due to a non-erroneous condition (such as a - * user cancelling the operation). + * @param filteredReports The filtered reports (may be incomplete if error is non-nil). * @param error Non-nil if an error occurred. */ -typedef void (^KSCrashReportFilterCompletion)(NSArray> *_Nullable filteredReports, BOOL completed, +typedef void (^KSCrashReportFilterCompletion)(NSArray> *_Nullable filteredReports, NSError *_Nullable error) NS_SWIFT_UNAVAILABLE("Use Swift closures instead!"); @@ -64,15 +60,14 @@ NS_SWIFT_NAME(CrashReportFilter) * * @param onCompletion The completion block. If nil, this function does nothing. * @param filteredReports The parameter to send as "filteredReports". - * @param completed The parameter to send as "completed". * @param error The parameter to send as "error". */ static inline void kscrash_callCompletion(KSCrashReportFilterCompletion _Nullable onCompletion, - NSArray> *_Nullable filteredReports, BOOL completed, + NSArray> *_Nullable filteredReports, NSError *_Nullable error) { if (onCompletion) { - onCompletion(filteredReports, completed, error); + onCompletion(filteredReports, error); } } diff --git a/Sources/KSCrashRecording/include/KSCrashReportStore.h b/Sources/KSCrashRecording/include/KSCrashReportStore.h index 21a2bc35..c43f20e7 100644 --- a/Sources/KSCrashRecording/include/KSCrashReportStore.h +++ b/Sources/KSCrashRecording/include/KSCrashReportStore.h @@ -99,10 +99,8 @@ NS_SWIFT_NAME(CrashReportStore) /** Send all outstanding crash reports to the current sink. * It will only attempt to send the most recent 5 reports. All others will be * deleted. Once the reports are successfully sent to the server, they may be - * deleted locally, depending on the property "deleteAfterSendAll". + * deleted locally, depending on the property "reportCleanupPolicy". * - * @note A call of `setupReportStoreWithPath:error:` or `installWithConfiguration:error:` is required - * before working with crash reports. * @note Property "sink" MUST be set or else this method will call `onCompletion` with an error. * * @param onCompletion Called when sending is complete (nil = ignore). @@ -110,9 +108,6 @@ NS_SWIFT_NAME(CrashReportStore) - (void)sendAllReportsWithCompletion:(nullable KSCrashReportFilterCompletion)onCompletion; /** Get report. - * - * @note A call of `setupReportStoreWithPath:error:` or `installWithConfiguration:error:` is required - * before working with crash reports. * * @param reportID An ID of report. * @@ -121,15 +116,10 @@ NS_SWIFT_NAME(CrashReportStore) - (nullable KSCrashReportDictionary *)reportForID:(int64_t)reportID NS_SWIFT_NAME(report(for:)); /** Delete all unsent reports. - * @note A call of `setupReportStoreWithPath:error:` or `installWithConfiguration:error:` is required - * before working with crash reports. */ - (void)deleteAllReports; /** Delete report. - * - * @note A call of `setupReportStoreWithPath:error:` or `installWithConfiguration:error:` is required - * before working with crash reports. * * @param reportID An ID of report to delete. */ diff --git a/Sources/KSCrashSinks/KSCrashReportSinkConsole.m b/Sources/KSCrashSinks/KSCrashReportSinkConsole.m index 1a53169a..17a1a577 100644 --- a/Sources/KSCrashSinks/KSCrashReportSinkConsole.m +++ b/Sources/KSCrashSinks/KSCrashReportSinkConsole.m @@ -57,7 +57,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras printf("Report %d:\n%s\n", ++i, report.value.UTF8String); } - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); } @end diff --git a/Sources/KSCrashSinks/KSCrashReportSinkEMail.m b/Sources/KSCrashSinks/KSCrashReportSinkEMail.m index 66b21319..d1c1afbf 100644 --- a/Sources/KSCrashSinks/KSCrashReportSinkEMail.m +++ b/Sources/KSCrashSinks/KSCrashReportSinkEMail.m @@ -98,22 +98,22 @@ - (void)mailComposeController:(__unused MFMailComposeViewController *)mailContro switch (result) { case MFMailComposeResultSent: - kscrash_callCompletion(self.onCompletion, self.reports, YES, nil); + kscrash_callCompletion(self.onCompletion, self.reports, nil); break; case MFMailComposeResultSaved: - kscrash_callCompletion(self.onCompletion, self.reports, YES, nil); + kscrash_callCompletion(self.onCompletion, self.reports, nil); break; case MFMailComposeResultCancelled: - kscrash_callCompletion(self.onCompletion, self.reports, NO, + kscrash_callCompletion(self.onCompletion, self.reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"User cancelled"]); break; case MFMailComposeResultFailed: - kscrash_callCompletion(self.onCompletion, self.reports, NO, error); + kscrash_callCompletion(self.onCompletion, self.reports, error); break; default: { - kscrash_callCompletion(self.onCompletion, self.reports, NO, + kscrash_callCompletion(self.onCompletion, self.reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Unknown MFMailComposeResult: %d", result]); @@ -220,7 +220,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; [keyWindow.rootViewController presentViewController:alertController animated:YES completion:NULL]; - kscrash_callCompletion(onCompletion, reports, NO, + kscrash_callCompletion(onCompletion, reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"E-Mail not enabled on device"]); @@ -240,8 +240,8 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras [process startWithController:mailController reports:reports filenameFmt:filenameFmt - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - kscrash_callCompletion(onCompletion, filteredReports, completed, error); + onCompletion:^(NSArray *filteredReports, NSError *error) { + kscrash_callCompletion(onCompletion, filteredReports, error); dispatch_async(dispatch_get_main_queue(), ^{ process = nil; }); @@ -278,7 +278,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras for (id report in reports) { NSLog(@"Report\n%@", report); } - kscrash_callCompletion(onCompletion, reports, NO, + kscrash_callCompletion(onCompletion, reports, [KSNSErrorHelper errorWithDomain:[[self class] description] code:0 description:@"Cannot send mail on this platform"]); diff --git a/Sources/KSCrashSinks/KSCrashReportSinkStandard.m b/Sources/KSCrashSinks/KSCrashReportSinkStandard.m index e7db8121..b567487f 100644 --- a/Sources/KSCrashSinks/KSCrashReportSinkStandard.m +++ b/Sources/KSCrashSinks/KSCrashReportSinkStandard.m @@ -89,7 +89,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras } NSData *jsonData = [KSJSONCodec encode:jsonArray options:KSJSONEncodeOptionSorted error:&error]; if (jsonData == nil) { - kscrash_callCompletion(onCompletion, reports, NO, error); + kscrash_callCompletion(onCompletion, reports, error); return; } @@ -115,12 +115,12 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras block:^{ [[KSHTTPRequestSender sender] sendRequest:request onSuccess:^(__unused NSHTTPURLResponse *response, __unused NSData *data) { - kscrash_callCompletion(onCompletion, reports, YES, nil); + kscrash_callCompletion(onCompletion, reports, nil); } onFailure:^(NSHTTPURLResponse *response, NSData *data) { NSString *text = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; kscrash_callCompletion( - onCompletion, reports, NO, + onCompletion, reports, [NSError errorWithDomain:[[self class] description] code:response.statusCode @@ -128,7 +128,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras forKey:NSLocalizedDescriptionKey]]); } onError:^(NSError *error2) { - kscrash_callCompletion(onCompletion, reports, NO, error2); + kscrash_callCompletion(onCompletion, reports, error2); }]; }]; } diff --git a/Tests/KSCrashDemangleFilterTests/KSCrashReportFilterDemangle_Tests.m b/Tests/KSCrashDemangleFilterTests/KSCrashReportFilterDemangle_Tests.m index 5dac3dab..929ea0e2 100644 --- a/Tests/KSCrashDemangleFilterTests/KSCrashReportFilterDemangle_Tests.m +++ b/Tests/KSCrashDemangleFilterTests/KSCrashReportFilterDemangle_Tests.m @@ -149,7 +149,7 @@ - (void)testReportDemangle XCTestExpectation *expectation = [self expectationWithDescription:@"Filter callback called"]; [filter filterReports:@[ mangledReport ] - onCompletion:^(NSArray> *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray> *filteredReports, NSError *error) { KSCrashReportDictionary *demangledReport = filteredReports.firstObject; XCTAssertEqualObjects(demangledReport, expectedReport); [expectation fulfill]; diff --git a/Tests/KSCrashFiltersTests/KSCrashReportFilterAlert_Tests.m b/Tests/KSCrashFiltersTests/KSCrashReportFilterAlert_Tests.m index ba9e4f29..da15130e 100644 --- a/Tests/KSCrashFiltersTests/KSCrashReportFilterAlert_Tests.m +++ b/Tests/KSCrashFiltersTests/KSCrashReportFilterAlert_Tests.m @@ -42,8 +42,7 @@ - (void)testAlert XCTestExpectation *expectation = [self expectationWithDescription:@"Filter completion"]; [filter filterReports:[NSArray array] - onCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(__unused NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); [expectation fulfill]; }]; diff --git a/Tests/KSCrashFiltersTests/KSCrashReportFilterGZip_Tests.m b/Tests/KSCrashFiltersTests/KSCrashReportFilterGZip_Tests.m index 51ba8bba..b904b171 100644 --- a/Tests/KSCrashFiltersTests/KSCrashReportFilterGZip_Tests.m +++ b/Tests/KSCrashFiltersTests/KSCrashReportFilterGZip_Tests.m @@ -60,8 +60,7 @@ - (void)testFilterGZipCompress { id filter = [KSCrashReportFilterGZipCompress filterWithCompressionLevel:-1]; [filter filterReports:self.decompressedReports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error2) { XCTAssertNil(error2, @""); XCTAssertEqualObjects(filteredReports, self.compressedReports, @""); }]; @@ -71,8 +70,7 @@ - (void)testFilterGZipDecompress { id filter = [KSCrashReportFilterGZipDecompress filter]; [filter filterReports:self.compressedReports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error2) { XCTAssertNil(error2, @""); XCTAssertEqualObjects(filteredReports, self.decompressedReports, @""); }]; diff --git a/Tests/KSCrashFiltersTests/KSCrashReportFilterJSON_Tests.m b/Tests/KSCrashFiltersTests/KSCrashReportFilterJSON_Tests.m index 53965665..adc4eff2 100644 --- a/Tests/KSCrashFiltersTests/KSCrashReportFilterJSON_Tests.m +++ b/Tests/KSCrashFiltersTests/KSCrashReportFilterJSON_Tests.m @@ -56,8 +56,7 @@ - (void)testFilterJSONEncode { id filter = [KSCrashReportFilterJSONEncode filterWithOptions:0]; [filter filterReports:self.decodedReports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error2) { XCTAssertNil(error2, @""); XCTAssertEqualObjects(filteredReports, self.encodedReports, @""); }]; @@ -71,8 +70,7 @@ - (void)testFilterJSONEncodeInvalid id filter = [KSCrashReportFilterJSONEncode filterWithOptions:0]; [filter filterReports:decoded - onCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertFalse(completed, @""); + onCompletion:^(__unused NSArray *filteredReports, NSError *error2) { XCTAssertNotNil(error2, @""); }]; } @@ -81,8 +79,7 @@ - (void)testFilterJSONDencode { id filter = [KSCrashReportFilterJSONDecode filterWithOptions:0]; [filter filterReports:self.encodedReports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error2) { XCTAssertNil(error2, @""); XCTAssertEqualObjects(filteredReports, self.decodedReports, @""); }]; @@ -96,8 +93,7 @@ - (void)testFilterJSONDencodeInvalid id filter = [KSCrashReportFilterJSONDecode filterWithOptions:0]; [filter filterReports:encoded - onCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error2) { - XCTAssertFalse(completed, @""); + onCompletion:^(__unused NSArray *filteredReports, NSError *error2) { XCTAssertNotNil(error2, @""); }]; } diff --git a/Tests/KSCrashFiltersTests/KSCrashReportFilter_Tests.m b/Tests/KSCrashFiltersTests/KSCrashReportFilter_Tests.m index ad149772..98443114 100644 --- a/Tests/KSCrashFiltersTests/KSCrashReportFilter_Tests.m +++ b/Tests/KSCrashFiltersTests/KSCrashReportFilter_Tests.m @@ -45,7 +45,7 @@ + (KSCrash_TestNilFilter *)filter - (void)filterReports:(__unused NSArray *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion { - onCompletion(nil, YES, nil); + onCompletion(nil, nil); } @end @@ -53,7 +53,6 @@ - (void)filterReports:(__unused NSArray *)reports onCompletion:(KSCrashReportFil @interface KSCrash_TestFilter : NSObject @property(nonatomic, readwrite, assign) NSTimeInterval delay; -@property(nonatomic, readwrite, assign) BOOL completed; @property(nonatomic, readwrite, strong) NSError *error; @property(nonatomic, readwrite, strong) NSTimer *timer; @property(nonatomic, readwrite, copy) NSArray> *reports; @@ -63,16 +62,15 @@ @interface KSCrash_TestFilter : NSObject @implementation KSCrash_TestFilter -+ (KSCrash_TestFilter *)filterWithDelay:(NSTimeInterval)delay completed:(BOOL)completed error:(NSError *)error ++ (KSCrash_TestFilter *)filterWithDelay:(NSTimeInterval)delay error:(NSError *)error { - return [[self alloc] initWithDelay:delay completed:completed error:error]; + return [[self alloc] initWithDelay:delay error:error]; } -- (id)initWithDelay:(NSTimeInterval)delay completed:(BOOL)completed error:(NSError *)error +- (id)initWithDelay:(NSTimeInterval)delay error:(NSError *)error { if ((self = [super init])) { _delay = delay; - _completed = completed; _error = error; } return self; @@ -95,7 +93,7 @@ - (void)filterReports:(NSArray> *)reports onCompletion:(KSCras - (void)onTimeUp { - kscrash_callCompletion(self.onCompletion, self.reports, self.completed, self.error); + kscrash_callCompletion(self.onCompletion, self.reports, self.error); } @end @@ -105,6 +103,7 @@ @interface KSCrashReportFilter_Tests : XCTestCase @property(nonatomic, copy) NSArray *reports; @property(nonatomic, copy) NSArray *reportsWithData; @property(nonatomic, copy) NSArray *reportsWithDict; +@property(nonatomic, strong) NSError *testError; @end @@ -131,6 +130,7 @@ - (void)setUp @"third" : @"b", }], ]; + self.testError = [NSError errorWithDomain:@"test" code:-23 userInfo:nil]; } - (void)testPassthroughLeak @@ -140,7 +140,7 @@ - (void)testPassthroughLeak __block KSCrashReportFilterPassthrough *filter = [KSCrashReportFilterPassthrough filter]; [filter filterReports:reports - onCompletion:^(__unused NSArray *filteredReports, __unused BOOL completed, __unused NSError *error) { + onCompletion:^(__unused NSArray *filteredReports, __unused NSError *error) { filter = nil; reports = nil; dispatch_async(dispatch_get_main_queue(), ^{ @@ -155,8 +155,7 @@ - (void)testPipeline filterWithFilters:[KSCrashReportFilterPassthrough filter], [KSCrashReportFilterPassthrough filter], nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; @@ -169,8 +168,7 @@ - (void)testPipelineInit filter = filter; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; @@ -181,23 +179,21 @@ - (void)testPipelineNoFilters id filter = [KSCrashReportFilterPipeline filterWithFilters:nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; } -- (void)testFilterPipelineIncomplete +- (void)testFilterPipelineError { id filter = [KSCrashReportFilterPipeline - filterWithFilters:[KSCrash_TestFilter filterWithDelay:0 completed:NO error:nil], nil]; + filterWithFilters:[KSCrash_TestFilter filterWithDelay:0 error:self.testError], nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertNotNil(filteredReports, @""); - XCTAssertFalse(completed, @""); - XCTAssertNil(error, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { + XCTAssertNotNil(filteredReports); + XCTAssertEqualObjects(error, self.testError); }]; } @@ -207,9 +203,8 @@ - (void)testFilterPipelineNilReports [KSCrashReportFilterPipeline filterWithFilters:[KSCrash_TestNilFilter filter], nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(filteredReports, @""); - XCTAssertFalse(completed, @""); XCTAssertNotNil(error, @""); }]; } @@ -217,18 +212,17 @@ - (void)testFilterPipelineNilReports - (void)testPiplelineLeak1 { __block NSArray *reports = [NSArray arrayWithArray:self.reports]; - __block id filter = [KSCrash_TestFilter filterWithDelay:0.1 completed:YES error:nil]; + __block id filter = [KSCrash_TestFilter filterWithDelay:0.1 error:nil]; __weak id weakReports = reports; __weak id weakFilter = filter; __block KSCrashReportFilterPipeline *pipeline = [KSCrashReportFilterPipeline filterWithFilters:filter, nil]; [pipeline filterReports:reports - onCompletion:^(__unused NSArray *filteredReports, __unused BOOL completed, __unused NSError *error) { + onCompletion:^(__unused NSArray *filteredReports, __unused NSError *error) { reports = nil; filter = nil; pipeline = nil; - XCTAssertTrue(completed, @""); dispatch_async(dispatch_get_main_queue(), ^{ XCTAssertNil(weakReports, @"Object leaked"); XCTAssertNil(weakFilter, @"Object leaked"); @@ -239,18 +233,17 @@ - (void)testPiplelineLeak1 - (void)testPiplelineLeak2 { __block NSArray *reports = [NSArray arrayWithArray:self.reports]; - __block id filter = [KSCrash_TestFilter filterWithDelay:0.1 completed:NO error:nil]; + __block id filter = [KSCrash_TestFilter filterWithDelay:0.1 error:nil]; __weak id weakReports = reports; __weak id weakFilter = filter; __block KSCrashReportFilterPipeline *pipeline = [KSCrashReportFilterPipeline filterWithFilters:filter, nil]; [pipeline filterReports:reports - onCompletion:^(__unused NSArray *filteredReports, __unused BOOL completed, __unused NSError *error) { + onCompletion:^(__unused NSArray *filteredReports, __unused NSError *error) { reports = nil; filter = nil; pipeline = nil; - XCTAssertFalse(completed, @""); dispatch_async(dispatch_get_main_queue(), ^{ XCTAssertNil(weakReports, @"Object leaked"); XCTAssertNil(weakFilter, @"Object leaked"); @@ -265,8 +258,7 @@ - (void)testFilterPassthrough id filter = [KSCrashReportFilterPassthrough filter]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; @@ -277,8 +269,7 @@ - (void)testFilterStringToData id filter = [KSCrashReportFilterStringToData filter]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reportsWithData, @""); }]; @@ -289,8 +280,7 @@ - (void)testFilterDataToString id filter = [KSCrashReportFilterDataToString filter]; [filter filterReports:self.reportsWithData - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; @@ -302,8 +292,7 @@ - (void)testFilterPipeline filterWithFilters:[KSCrashReportFilterStringToData filter], [KSCrashReportFilterDataToString filter], nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects(filteredReports, self.reports, @""); }]; @@ -316,8 +305,7 @@ - (void)testFilterCombine [KSCrashReportFilterStringToData filter], @"data", nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); for (NSUInteger i = 0; i < self.reports.count; i++) { id exp1 = [[self.reports objectAtIndex:i] value]; @@ -341,8 +329,7 @@ - (void)testFilterCombineInit filter = filter; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); for (NSUInteger i = 0; i < [self.reports count]; i++) { id exp1 = [[self.reports objectAtIndex:i] value]; @@ -363,8 +350,7 @@ - (void)testFilterCombineNoFilters id filter = [KSCrashReportFilterCombine filterWithFiltersAndKeys:nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); for (NSUInteger i = 0; i < [self.reports count]; i++) { id exp = [self.reports objectAtIndex:i]; @@ -377,13 +363,12 @@ - (void)testFilterCombineNoFilters - (void)testFilterCombineIncomplete { id filter = [KSCrashReportFilterCombine - filterWithFiltersAndKeys:[KSCrash_TestFilter filterWithDelay:0 completed:NO error:nil], @"Blah", nil]; + filterWithFiltersAndKeys:[KSCrash_TestFilter filterWithDelay:0 error:self.testError], @"Blah", nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNotNil(filteredReports, @""); - XCTAssertFalse(completed, @""); - XCTAssertNil(error, @""); + XCTAssertEqualObjects(error, self.testError, @""); }]; } @@ -393,9 +378,8 @@ - (void)testFilterCombineNilReports [KSCrashReportFilterCombine filterWithFiltersAndKeys:[KSCrash_TestNilFilter filter], @"Blah", nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(filteredReports, @""); - XCTAssertFalse(completed, @""); XCTAssertNotNil(error, @""); }]; } @@ -407,8 +391,7 @@ - (void)testFilterCombineArray [NSArray arrayWithObject:[KSCrashReportFilterStringToData filter]], @"data", nil]; [filter filterReports:self.reports - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); for (NSUInteger i = 0; i < [self.reports count]; i++) { id exp1 = [[self.reports objectAtIndex:i] value]; @@ -433,8 +416,7 @@ - (void)testFilterCombineMissingKey nil]; [filter filterReports:self.reports - onCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertFalse(completed, @""); + onCompletion:^(__unused NSArray *filteredReports, NSError *error) { XCTAssertNotNil(error, @""); }]; } @@ -446,8 +428,7 @@ - (void)testConcatenate keys:@"first", @"second", nil]; [filter filterReports:self.reportsWithDict - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects([filteredReports objectAtIndex:0], expected, @""); }]; @@ -461,8 +442,7 @@ - (void)testConcatenateInit filter = filter; [filter filterReports:self.reportsWithDict - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects([filteredReports objectAtIndex:0], expected, @""); }]; @@ -477,8 +457,7 @@ - (void)testSubset id filter = [KSCrashReportFilterSubset filterWithKeys:@"first", @"third", nil]; [filter filterReports:self.reportsWithDict - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects([filteredReports objectAtIndex:0], expected, @""); }]; @@ -489,8 +468,7 @@ - (void)testSubsetBadKeyPath id filter = [KSCrashReportFilterSubset filterWithKeys:@"first", @"aaa", nil]; [filter filterReports:self.reportsWithDict - onCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertFalse(completed, @""); + onCompletion:^(__unused NSArray *filteredReports, NSError *error) { XCTAssertNotNil(error, @""); }]; } @@ -505,8 +483,7 @@ - (void)testSubsetInit filter = filter; [filter filterReports:self.reportsWithDict - onCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertTrue(completed, @""); + onCompletion:^(NSArray *filteredReports, NSError *error) { XCTAssertNil(error, @""); XCTAssertEqualObjects([filteredReports objectAtIndex:0], expected, @""); }]; diff --git a/Tests/KSCrashInstallationsTests/KSCrashInstallationEmail_Tests.m b/Tests/KSCrashInstallationsTests/KSCrashInstallationEmail_Tests.m index 39f93e65..0e297e9c 100644 --- a/Tests/KSCrashInstallationsTests/KSCrashInstallationEmail_Tests.m +++ b/Tests/KSCrashInstallationsTests/KSCrashInstallationEmail_Tests.m @@ -42,9 +42,8 @@ - (void)testInstall installation.filenameFmt = @"someFile.txt.gz"; [installation addConditionalAlertWithTitle:@"title" message:@"message" yesAnswer:@"Yes" noAnswer:@"No"]; [installation installWithConfiguration:[KSCrashConfiguration new] error:NULL]; - [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { + [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, NSError *error) { // There are no reports, so this will succeed. - XCTAssertTrue(completed, @""); XCTAssertNil(error, @""); }]; } @@ -61,8 +60,7 @@ - (void)testInstallInvalid #pragma clang diagnostic pop [installation addUnconditionalAlertWithTitle:@"title" message:@"message" dismissButtonText:@"dismiss"]; [installation installWithConfiguration:[KSCrashConfiguration new] error:NULL]; - [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { - XCTAssertFalse(completed, @""); + [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, NSError *error) { XCTAssertNotNil(error, @""); }]; } diff --git a/Tests/KSCrashInstallationsTests/KSCrashInstallationStandard_Tests.m b/Tests/KSCrashInstallationsTests/KSCrashInstallationStandard_Tests.m index e4bd6422..f6a7f8aa 100644 --- a/Tests/KSCrashInstallationsTests/KSCrashInstallationStandard_Tests.m +++ b/Tests/KSCrashInstallationsTests/KSCrashInstallationStandard_Tests.m @@ -38,9 +38,8 @@ - (void)testInstall KSCrashInstallationStandard *installation = [KSCrashInstallationStandard sharedInstance]; installation.url = [NSURL URLWithString:@"www.google.com"]; [installation installWithConfiguration:[KSCrashConfiguration new] error:NULL]; - [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, BOOL completed, NSError *error) { + [installation sendAllReportsWithCompletion:^(__unused NSArray *filteredReports, NSError *error) { // There are no reports, so this will succeed. - XCTAssertTrue(completed, @""); XCTAssertNil(error, @""); }]; }