From 1e7fb8e2834ed0d2d1462d8e167ed178824604a8 Mon Sep 17 00:00:00 2001 From: melek <127785723+melekr@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:58:44 -0400 Subject: [PATCH] Generate Report with exception (#142) --- Backtrace.podspec | 2 +- Package.resolved | 4 ++-- Package.swift | 2 +- Podfile | 2 +- Podfile.lock | 12 ++++++------ Sources/Public/BacktraceCrashReporter.swift | 3 ++- Tests/CrashReporterTests.swift | 15 +++++++++++++++ 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Backtrace.podspec b/Backtrace.podspec index 5660cce2..555a4742 100644 --- a/Backtrace.podspec +++ b/Backtrace.podspec @@ -32,7 +32,7 @@ Pod::Spec.new do |s| s.osx.public_header_files = ["Backtrace-macOS/**/*.h*"] s.tvos.public_header_files = ["Backtrace-tvOS/**/*.h*"] s.static_framework = true - s.dependency "PLCrashReporter", '1.11' + s.dependency "PLCrashReporter", '1.11.1' s.resource_bundle = { 'BacktraceResources' => ['Sources/**/*.xcdatamodeld','Sources/Resources/*.xcprivacy']} end diff --git a/Package.resolved b/Package.resolved index 776fbcbe..e38bee44 100644 --- a/Package.resolved +++ b/Package.resolved @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/microsoft/plcrashreporter.git", "state": { "branch": null, - "revision": "b1a342da19ed9b3af61ea2efa7656c2af30aeb7c", - "version": "1.11.0" + "revision": "1aed8f7dc79ce8e674c61e430ef51ca3db18cea9", + "version": "1.11.1" } }, { diff --git a/Package.swift b/Package.swift index ed884334..725c2eb5 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( .library(name: "Backtrace", targets: ["Backtrace"]) ], dependencies: [ - .package(url: "https://github.com/microsoft/plcrashreporter.git", from: "1.11.0"), + .package(url: "https://github.com/microsoft/plcrashreporter.git", .exact("1.11.1")), .package(url: "https://github.com/Quick/Nimble.git", from: "10.0.0"), .package(url: "https://github.com/Quick/Quick.git", from: "5.0.1") ], diff --git a/Podfile b/Podfile index 9d0fe47e..cce78aca 100644 --- a/Podfile +++ b/Podfile @@ -6,7 +6,7 @@ project 'Backtrace.xcworkspace' # Definitions def shared_pods # Define shared CocoaPods here - pod 'PLCrashReporter', '1.11' + pod 'PLCrashReporter', '1.11.1' end def shared_test_pods diff --git a/Podfile.lock b/Podfile.lock index b37ca353..2e0d2c9d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,14 +1,14 @@ PODS: - Backtrace (2.0.5-alpha1): - - PLCrashReporter (= 1.11) + - PLCrashReporter (= 1.11.1) - Nimble (10.0.0) - - PLCrashReporter (1.11.0) + - PLCrashReporter (1.11.1) - Quick (5.0.1) DEPENDENCIES: - Backtrace (from `./Backtrace.podspec`) - Nimble (~> 10.0.0) - - PLCrashReporter (= 1.11) + - PLCrashReporter (= 1.11.1) - Quick (~> 5.0.1) SPEC REPOS: @@ -22,11 +22,11 @@ EXTERNAL SOURCES: :path: "./Backtrace.podspec" SPEC CHECKSUMS: - Backtrace: fd2750f1fae07c5fe5540543fdbf8c46ec0280c9 + Backtrace: 060b3cf69aa69a4a080d1e713f8b3047f932d921 Nimble: 5316ef81a170ce87baf72dd961f22f89a602ff84 - PLCrashReporter: 7a9dff14a23ba5d2e28c6160f0bb6fada5e71a8d + PLCrashReporter: 5d2d3967afe0efad61b3048d617e2199a5d1b787 Quick: 749aa754fd1e7d984f2000fe051e18a3a9809179 -PODFILE CHECKSUM: 9879217fb9b028733c19f11520859f8869f67aba +PODFILE CHECKSUM: 57ff1dc221e0d36eb96c410cf8f411fed4e969f5 COCOAPODS: 1.15.2 diff --git a/Sources/Public/BacktraceCrashReporter.swift b/Sources/Public/BacktraceCrashReporter.swift index 7d7f387a..aa481f35 100644 --- a/Sources/Public/BacktraceCrashReporter.swift +++ b/Sources/Public/BacktraceCrashReporter.swift @@ -51,7 +51,8 @@ extension BacktraceCrashReporter: CrashReporting { attributes: Attributes, attachmentPaths: [String] = []) throws -> BacktraceReport { - return try BacktraceReport(report: reporter.generateLiveReport(), attributes: attributes, attachmentPaths: attachmentPaths) + let reportData = try reporter.generateLiveReport(with: exception) + return try BacktraceReport(report: reportData, attributes: attributes, attachmentPaths: attachmentPaths) } func enableCrashReporting() throws { diff --git a/Tests/CrashReporterTests.swift b/Tests/CrashReporterTests.swift index 8f4875d9..42fc2f30 100644 --- a/Tests/CrashReporterTests.swift +++ b/Tests/CrashReporterTests.swift @@ -20,11 +20,26 @@ final class CrashReporterTests: QuickSpec { it("generates live report on demand") { expect { try crashReporter.generateLiveReport(attributes: [:]) }.toNot(throwError()) } + it("generate live report on demand 10 times") { for _ in 0...10 { expect { try crashReporter.generateLiveReport(attributes: [:]) }.toNot(throwError()) } } + + it("generated live report without exception") { + let reportData = try crashReporter.generateLiveReport(exception: nil, attributes: [:]) + + expect { reportData.plCrashReport.exceptionInfo }.to(beNil()) + } + + it("generated live report contains exception") { + let exception = NSException(name: NSExceptionName.decimalNumberOverflowException, reason: "Test Spec") + let reportData = try crashReporter.generateLiveReport(exception: exception, attributes: [:]) + + expect { reportData.plCrashReport.exceptionInfo.exceptionName }.to(equal(NSExceptionName.decimalNumberOverflowException.rawValue)) + expect { reportData.plCrashReport.exceptionInfo.exceptionReason }.to(equal("Test Spec")) + } } } }