Skip to content

Commit df19413

Browse files
committed
Make SentryCrashBridge non null
1 parent 04d2f72 commit df19413

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

Sources/Sentry/include/SentryCrash.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ SENTRY_NO_INIT
6666
/** Cache directory base path. */
6767
@property (nonatomic, readwrite, retain) NSString *basePath;
6868

69-
/** Bridge to SDK services (notification center, date provider, crash reporter). */
70-
@property (nonatomic, strong, nullable) SentryCrashBridge *bridge;
69+
/** Bridge to SDK services (notification center, date provider, crash reporter).
70+
* Must be set before calling install. */
71+
@property (nonatomic, strong) SentryCrashBridge *bridge;
7172

7273
/** A dictionary containing any info you'd like to appear in crash reports. Must
7374
* contain only JSON-safe data: NSString for keys, and NSDictionary, NSArray,

Sources/Sentry/include/SentryCrashInstallation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ NS_ASSUME_NONNULL_BEGIN
6363
- (void)sendAllReportsWithCompletion:(nullable SentryCrashReportFilterCompletion)onCompletion;
6464

6565
/** Bridge for accessing SDK services without dependency container.
66-
* Set by SentryCrashIntegration before installation. */
67-
@property (nonatomic, strong, nullable) SentryCrashBridge *bridge;
66+
* Must be set by SentryCrashIntegration before calling install. */
67+
@property (nonatomic, strong) SentryCrashBridge *bridge;
6868

6969
@end
7070

Tests/SentryTests/SentryCrash/SentryCrashInstallationTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ class SentryCrashInstallationTests: XCTestCase {
7373
#endif // os(iOS) || os(tvOS)
7474
}
7575

76+
func testInstall_SetsUncaughtExceptionHandler() {
77+
// Verifies the bridge is set before sentrycrash_install so that when
78+
// the NSException monitor calls setEnabled(true), g_bridge is non-nil
79+
// and uncaughtExceptionHandler gets assigned on the crash reporter.
80+
// Previously, setBridge was called after install, so the assignment
81+
// was a no-op via ObjC nil messaging.
82+
let installation = getSut()
83+
let crashReporter = SentryDependencyContainer.sharedInstance().crashReporter
84+
85+
// Uninstall first to reset g_installed and disable all monitors.
86+
// g_installed is a static that persists across tests; if it's
87+
// already 1, sentrycrash_install short-circuits and monitors are
88+
// never re-enabled through the full setEnabled(true) path.
89+
crashReporter.uninstall()
90+
91+
installation.install("/private/tmp")
92+
defer { installation.uninstall() }
93+
94+
XCTAssertNotNil(
95+
crashReporter.uncaughtExceptionHandler,
96+
"uncaughtExceptionHandler should be set after install because the bridge must be available when the NSException monitor is enabled"
97+
)
98+
}
99+
76100
// MARK: - Private
77101

78102
private func getSut() -> SentryCrashTestInstallation {

0 commit comments

Comments
 (0)