Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 23 additions & 12 deletions platform/swift/source/Capture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,34 @@ extension Logger {
///
/// - parameter type: mechanism for crash detection
public static func initFatalIssueReporting(_ type: IssueReporterType = .customConfig) {
switch type {
case .builtIn:
if let outputDir = Logger.reportCollectionDirectory() {
if issueReporterInitResult.0 != .notInitialized {
log(level: .warning, message: "Fatal issue reporting already being initialized")
return
}

issueReporterInitResult = (.initializing, 0)
guard let outputDir = Logger.reportCollectionDirectory() else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a check at different places within both type logic branches, so we can instead have one check at the beginning

log(level: .warning, message: "Fatal issue reporting output directory not defined, cannot enable reporting")
issueReporterInitResult = (.initialized(.missingReportsDirectory), 0)
return
}

issueReporterInitResult = measureTime {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this to the top level instead of nested in the individual types

switch type {
case .builtIn:
#if targetEnvironment(simulator)
log(level: .info, message: "Fatal issue reporting disabled for simulated devices")
return .initialized(.unsupportedHardware)
#else
let reporter = DiagnosticEventReporter(outputDir: outputDir, sdkVersion: capture_get_sdk_version())
diagnosticReporter.update { val in
val = reporter
}
MXMetricManager.shared.add(reporter)
} else {
log(level: .warning, message: "Fatal issue reporting output directory not defined, cannot enable reporting")
}
case .customConfig:
if issueReporterInitResult.0 == .notInitialized {
issueReporterInitResult = (.initializing, 0)
issueReporterInitResult = CustomConfigIssueReporter.processFiles()
} else {
log(level: .warning, message: "Fatal issue reporting already being initialized")
return .initialized(.monitoring)
#endif
case .customConfig:
return CustomConfigIssueReporter.processFiles()
}
}
}
Expand Down
31 changes: 23 additions & 8 deletions platform/swift/source/reports/CustomConfigIssueReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@ enum IssueReporterInitState: Equatable {

/// Final state of an initialized crash reporter
enum ReporterInitResolution: Equatable, Error {
/// Found and delivered reports
case sent
/// Enabled monitoring for reports, may or may not detect any
case monitoring
/// Disabled due to hardware limitations
case unsupportedHardware
/// Did not find any reports to deliver, checking completed
case withoutPriorCrash
/// No crash reporting configuration found, cannot continue
case missingConfigFile
/// No directory available for delivering reports, cannot continue
case missingReportsDirectory
/// Crash reporting configuration file contains errors, cannot continue
case malformedConfigFile
/// Other kinds of errors occurred, cannot continue
case processingFailure(String)
}

Expand All @@ -40,14 +51,12 @@ struct CustomConfigIssueReporter {
case max = 10_000_000
}

static func processFiles() -> IssueReporterInitResult {
return measureTime {
switch readAndVerifyConfig() {
case .success(let (config, destDir)):
return copyFiles(config: config, destDir: destDir)
case .failure(let resolution):
return .initialized(resolution)
}
static func processFiles() -> IssueReporterInitState {
switch readAndVerifyConfig() {
case .success(let (config, destDir)):
return copyFiles(config: config, destDir: destDir)
case .failure(let resolution):
return .initialized(resolution)
}
}

Expand Down Expand Up @@ -195,12 +204,18 @@ extension IssueReporterInitState: CustomStringConvertible {
return "INITIALIZING"
case .initialized(let resolution):
switch resolution {
case .monitoring:
return "CRASH_REPORT_MONITORING"
case .sent:
return "CRASH_REPORT_SENT"
case .unsupportedHardware:
return "UNSUPPORTED_HARDWARE"
case .withoutPriorCrash:
return "NO_PRIOR_CRASHES"
case .missingConfigFile:
return "MISSING_CRASH_CONFIG_FILE"
case .missingReportsDirectory:
return "MISSING_CRASH_REPORT_DIR"
case .malformedConfigFile:
return "MALFORMED_CRASH_CONFIG_FILE"
case .processingFailure(let error):
Expand Down
Loading