Skip to content

Commit 5cfce5e

Browse files
alwxclaude
andcommitted
fix(ios): Guard against nil NSData and pin tests to SPI import
Two fixes flagged by Warden: 1. `RNSentryInternal.envelope(fromData:)` accepted a non-optional Swift `Data`. If the ObjC caller passed a nil `NSData*` (e.g. from a failed base64 decode of the envelope payload), the ObjC→Swift bridge would force-unwrap it and crash before the method body ran. Change the parameter to `Data?` with an internal `guard let` — matches the nil-tolerant behaviour of the deprecated `PrivateSentrySDKOnly.envelopeWithData:`. 2. Swift Cocoa tests accessed `SentrySDK.internal.*` with plain `import Sentry`. The `.internal` accessor is public today, but the sub-APIs the tests touch (`options`, `appStart`, `performance`) sit next to `@_spi(Private)`-gated siblings on the same struct. Add `@_spi(Private) import Sentry` to `RNSentryStartTests.swift`, `RNSentryStartFromFileTests.swift`, and `RNSentryReplayOptionsTests.swift` so they keep compiling if the surface is ever tightened. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 7becfaa commit 5cfce5e

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryReplayOptionsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sentry
1+
@_spi(Private) import Sentry
22
import XCTest
33

44
// File length grows as replay option coverage is added; lint runs with `--strict`.

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartFromFileTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sentry
1+
@_spi(Private) import Sentry
22
import XCTest
33

44
final class RNSentryStartFromFileTests: XCTestCase {

packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sentry
1+
@_spi(Private) import Sentry
22
import XCTest
33

44
final class RNSentryStartTests: XCTestCase {

packages/core/ios/RNSentryInternal.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,13 @@ import Foundation
8282

8383
// MARK: - Envelope
8484

85-
@_spi(Private) @objc public static func envelope(fromData data: Data) -> SentryEnvelope? {
86-
SentrySDK.internal.envelope.deserialize(from: data)
85+
// Accepts `Data?` (nil-safe) rather than `Data` so the ObjC bridge boundary
86+
// doesn't force-unwrap a nil `NSData*` from a failed base64 decode — that
87+
// would crash before we ever get a chance to check the result. Matches the
88+
// nil-tolerant behaviour of the deprecated `PrivateSentrySDKOnly.envelopeWithData:`.
89+
@_spi(Private) @objc public static func envelope(fromData data: Data?) -> SentryEnvelope? {
90+
guard let data = data else { return nil }
91+
return SentrySDK.internal.envelope.deserialize(from: data)
8792
}
8893

8994
@_spi(Private) @objc public static func capture(_ envelope: SentryEnvelope) {

0 commit comments

Comments
 (0)