Skip to content

Commit 1b5ded9

Browse files
authored
[WIP] React Native (#124)
* Fix crashed thread * Fix memory address, Add react native crash with address and stacktrace * Add tests for react native crash stacktrace * Switched everything to UInt instead of UInt64 * Moved alot of code into seperate extensions * Add setter for client extra and tags * Remove empty lines * Add addExtra and addTag to SentryClient and Event * Fix swift 2 syntax
1 parent a5df1e7 commit 1b5ded9

25 files changed

+5762
-239
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ Carthage/Checkouts
4848
fastlane/test_output/
4949
report.xml
5050
.env
51+
cobertura.xml

Sentry.xcodeproj/project.pbxproj

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@
118118
6320331F1E3A4BCE00E6318F /* Crash-missing-user.json in Resources */ = {isa = PBXBuildFile; fileRef = 632033101E3A4BCE00E6318F /* Crash-missing-user.json */; };
119119
632496061DEC33EA0014A044 /* SentrySwizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632495C01DE70EFD0014A044 /* SentrySwizzle.swift */; };
120120
6324960D1DEC33EE0014A044 /* SentrySwizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632495C01DE70EFD0014A044 /* SentrySwizzle.swift */; };
121+
6332A20B1E49AD1C0099D77A /* Sentry+UserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */; };
122+
6332A20D1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
123+
6332A20E1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
124+
6332A20F1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
125+
6332A2101E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
126+
6332A2121E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
127+
6332A2131E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
128+
6332A2141E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
129+
6332A2151E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
121130
633C38171E01952E00A74C63 /* SentryReactNativeCrashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633C38161E01952E00A74C63 /* SentryReactNativeCrashTests.swift */; };
122131
634EA0211DF85BF000FE83A9 /* Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 634EA0201DF85BF000FE83A9 /* Frame.swift */; };
123132
6350F6631DCE1C6B00B6B596 /* SentryCrashProbeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6350F6621DCE1C6B00B6B596 /* SentryCrashProbeTests.swift */; };
@@ -403,6 +412,9 @@
403412
6320330F1E3A4BCE00E6318F /* Crash-missing-crash.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Crash-missing-crash.json"; sourceTree = "<group>"; };
404413
632033101E3A4BCE00E6318F /* Crash-missing-user.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Crash-missing-user.json"; sourceTree = "<group>"; };
405414
632495C01DE70EFD0014A044 /* SentrySwizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SentrySwizzle.swift; path = ios/SentrySwizzle.swift; sourceTree = "<group>"; };
415+
6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Sentry+UserFeedback.swift"; path = "ios/Sentry+UserFeedback.swift"; sourceTree = "<group>"; };
416+
6332A20C1E49B28B0099D77A /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
417+
6332A2111E49B3680099D77A /* Sentry+Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Sentry+Event.swift"; sourceTree = "<group>"; };
406418
633C38161E01952E00A74C63 /* SentryReactNativeCrashTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryReactNativeCrashTests.swift; sourceTree = "<group>"; };
407419
634EA0201DF85BF000FE83A9 /* Frame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Frame.swift; sourceTree = "<group>"; };
408420
6350F6621DCE1C6B00B6B596 /* SentryCrashProbeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryCrashProbeTests.swift; sourceTree = "<group>"; };
@@ -565,6 +577,7 @@
565577
036378281C225D5200644C01 /* Sentry.h */,
566578
0363782B1C225D8300644C01 /* Sentry.swift */,
567579
632495C01DE70EFD0014A044 /* SentrySwizzle.swift */,
580+
6332A20C1E49B28B0099D77A /* Log.swift */,
568581
);
569582
path = Sources;
570583
sourceTree = "<group>";
@@ -707,6 +720,16 @@
707720
name = Network;
708721
sourceTree = "<group>";
709722
};
723+
6332A2031E49ACF90099D77A /* Sentry */ = {
724+
isa = PBXGroup;
725+
children = (
726+
8092F8E41CF2499600634F3F /* Sentry+Error.swift */,
727+
6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */,
728+
6332A2111E49B3680099D77A /* Sentry+Event.swift */,
729+
);
730+
name = Sentry;
731+
sourceTree = "<group>";
732+
};
710733
63CDAB411DD9D7F300B63921 /* Products */ = {
711734
isa = PBXGroup;
712735
children = (
@@ -763,6 +786,7 @@
763786
9B02CAB11CF5C1E8004F614C /* Extensions */ = {
764787
isa = PBXGroup;
765788
children = (
789+
6332A2031E49ACF90099D77A /* Sentry */,
766790
9B02CABA1CF5C25D004F614C /* Foundation */,
767791
9B02CAB51CF5C1F9004F614C /* Swift */,
768792
);
@@ -772,7 +796,6 @@
772796
9B02CAB51CF5C1F9004F614C /* Swift */ = {
773797
isa = PBXGroup;
774798
children = (
775-
8092F8E41CF2499600634F3F /* Sentry+Error.swift */,
776799
9B02CAB61CF5C20F004F614C /* Dictionary+Extras.swift */,
777800
);
778801
name = Swift;
@@ -1254,12 +1277,14 @@
12541277
files = (
12551278
03817D801D301E1D005A674A /* Contexts.swift in Sources */,
12561279
03C7152C1CE4DB940080AE60 /* Breadcrumb.swift in Sources */,
1280+
6332A2141E49B3680099D77A /* Sentry+Event.swift in Sources */,
12571281
630271D71E377ECC0047DC3B /* MemoryAddress.swift in Sources */,
12581282
63571EEE1DFE99E6001924CD /* BinaryImage.swift in Sources */,
12591283
63D54E5E1E0A7D790005B07A /* RequestOperation.swift in Sources */,
12601284
9B02CAB91CF5C20F004F614C /* Dictionary+Extras.swift in Sources */,
12611285
6350F6751DCE2F0A00B6B596 /* CrashReportConverter.swift in Sources */,
12621286
03C715271CE4DB910080AE60 /* Event.swift in Sources */,
1287+
6332A20F1E49B28B0099D77A /* Log.swift in Sources */,
12631288
03C715241CE4DB8D0080AE60 /* Sentry.swift in Sources */,
12641289
8092F8EA1CF2594100634F3F /* Sentry+Error.swift in Sources */,
12651290
03C7152A1CE4DB910080AE60 /* EventSerializable.swift in Sources */,
@@ -1311,6 +1336,7 @@
13111336
files = (
13121337
03817D7E1D301E1D005A674A /* Contexts.swift in Sources */,
13131338
630271F11E3A368D0047DC3B /* QueueableRequestManager.swift in Sources */,
1339+
6332A20D1E49B28B0099D77A /* Log.swift in Sources */,
13141340
03A89AA11CAACA6F00D94E22 /* BreadcrumbStore.swift in Sources */,
13151341
03CFCEC31C612F5300999EB7 /* CrashHandler.swift in Sources */,
13161342
8092F8E51CF2499600634F3F /* Sentry+Error.swift in Sources */,
@@ -1329,6 +1355,7 @@
13291355
03C1E5A71C57192A004D68D8 /* EventOffline.swift in Sources */,
13301356
63571EEC1DFE99E6001924CD /* BinaryImage.swift in Sources */,
13311357
63CDAB8C1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
1358+
6332A2121E49B3680099D77A /* Sentry+Event.swift in Sources */,
13321359
630271C61E37701E0047DC3B /* Register.swift in Sources */,
13331360
03C1E26A1D4652180004A612 /* Thread.swift in Sources */,
13341361
03E3D1F81C3E1A2800F00547 /* DSN.swift in Sources */,
@@ -1365,6 +1392,7 @@
13651392
isa = PBXSourcesBuildPhase;
13661393
buildActionMask = 2147483647;
13671394
files = (
1395+
6332A20E1E49B28B0099D77A /* Log.swift in Sources */,
13681396
63571E8E1DFAAD41001924CD /* Frame.swift in Sources */,
13691397
03817D7F1D301E1D005A674A /* Contexts.swift in Sources */,
13701398
03C736E21C474715004428DF /* CrashHandler.swift in Sources */,
@@ -1395,8 +1423,10 @@
13951423
036378331C227C7900644C01 /* Event.swift in Sources */,
13961424
9BF8E80A1E3B5B6900A417AE /* Functions.swift in Sources */,
13971425
03A89AA21CAACA6F00D94E22 /* BreadcrumbStore.swift in Sources */,
1426+
6332A2131E49B3680099D77A /* Sentry+Event.swift in Sources */,
13981427
632496061DEC33EA0014A044 /* SentrySwizzle.swift in Sources */,
13991428
63CDAB8D1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
1429+
6332A20B1E49AD1C0099D77A /* Sentry+UserFeedback.swift in Sources */,
14001430
03D4D9FA1CA48FA800799CC9 /* Breadcrumb.swift in Sources */,
14011431
03E3D1D81C3E166800F00547 /* EventSerializable.swift in Sources */,
14021432
63CDAB871DDC51E400B63921 /* UserFeedbackTableViewController.swift in Sources */,
@@ -1430,6 +1460,7 @@
14301460
files = (
14311461
63CDAB3B1DD9D4AE00B63921 /* CrashHandler.swift in Sources */,
14321462
630271F41E3A368D0047DC3B /* QueueableRequestManager.swift in Sources */,
1463+
6332A2101E49B28B0099D77A /* Log.swift in Sources */,
14331464
63CDAB2D1DD9D49700B63921 /* Dictionary+Extras.swift in Sources */,
14341465
63CDAB371DD9D4A800B63921 /* Contexts.swift in Sources */,
14351466
63CDAB3D1DD9D4AE00B63921 /* CrashReportConverter.swift in Sources */,
@@ -1448,6 +1479,7 @@
14481479
63CDAB8F1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
14491480
63571EEF1DFE99E6001924CD /* BinaryImage.swift in Sources */,
14501481
63CDAB301DD9D4A000B63921 /* EventProperties.swift in Sources */,
1482+
6332A2151E49B3680099D77A /* Sentry+Event.swift in Sources */,
14511483
630271C91E37701E0047DC3B /* Register.swift in Sources */,
14521484
63CDAB3A1DD9D4A800B63921 /* DebugMeta.swift in Sources */,
14531485
63CDAB281DD9D48500B63921 /* Sentry.swift in Sources */,

SentryTests/SentryCrashProbeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SentrySwiftCrashProbeTests: XCTestCase {
2727
let mechanism = event?.exceptions?.first?.mechanism
2828
let posixSignal = mechanism?["posix_signal"] as? [String: AnyType]
2929
let machException = mechanism?["mach_exception"] as? [String: AnyType]
30-
XCTAssertEqual(mechanism?["relevant_address"] as? String, "0x9660f06")
30+
XCTAssertEqual(mechanism?["relevant_address"] as? String, "0x109660f06")
3131
XCTAssertEqual(posixSignal?["signal"] as? Int, 6)
3232
XCTAssertEqual(machException?["exception"] as? Int, 10)
3333
}

SentryTests/SentryCrashTests.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,28 @@ class SentrySwiftCrashTests: XCTestCase {
2828
XCTAssertEqual(hexAddress?.asHex(), "0x3157e63d")
2929
XCTAssertEqual(hexAddress?.asInt(), 827844157)
3030

31-
let hexAddress2 = MemoryAddress(nil)
32-
XCTAssertNil(hexAddress2)
33-
XCTAssertNil(hexAddress2?.asHex())
34-
3531
let hexAddress3 = MemoryAddress(String(
3632
bytes: [0xD8, 0x00] as [UInt8],
37-
encoding: String.Encoding.utf16BigEndian) as? AnyObject)
33+
encoding: String.Encoding.utf16BigEndian))
3834
XCTAssertNil(hexAddress3)
3935

40-
let hexAddress4 = MemoryAddress("ö" as? AnyObject)
36+
let hexAddress4 = MemoryAddress("ö")
4137
XCTAssertNil(hexAddress4)
38+
39+
let hexAddress5 = MemoryAddress("0xxx123")
40+
XCTAssertNil(hexAddress5)
41+
42+
let hexAddress6 = MemoryAddress("0xA")
43+
XCTAssertEqual(hexAddress6?.asInt(), 10)
44+
45+
let hexAddress7 = MemoryAddress("0x3157e63d")
46+
XCTAssertEqual(hexAddress7?.asInt(), 827844157)
47+
48+
let hexAddress8 = MemoryAddress(MemoryAddress("0x1035AB510")?.asInt() as AnyObject?)
49+
XCTAssertEqual(hexAddress8?.asInt(), 4351243536)
50+
51+
let hexAddress9 = MemoryAddress(MemoryAddress(4351243536 as AnyObject?)?.asHex())
52+
XCTAssertEqual(hexAddress9?.asInt(), 4351243536)
4253
}
4354
#endif
4455

SentryTests/SentryObjCTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ - (void)testThatThingsCompileBecauseSwiftToOjbCBridge {
4242
@"some_things": @[@"green", @"red"],
4343
@"foobar": @{@"foo": @"bar"}
4444
};
45-
45+
[[SentryClient shared] addExtra:@"__sentry_stack" value:@"__sentry_stack"];
4646
SentryClient *nilClient = nil;
4747
[nilClient captureMessage:@"Some plain message from ObjC" level:SentrySeverityInfo];
4848

SentryTests/SentryReactNativeCrashTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class SentrySwiftReactNativeCrashTests: XCTestCase {
3232
XCTAssertNotNil(event)
3333
XCTAssertEqual(event?.threads?.last?.name, "React Native")
3434
XCTAssertEqual(event?.threads?.last?.stacktrace?.frames.first?.fileName, "/main.jsbundle")
35+
36+
let crashedThreads = event?.threads?.filter({ $0.crashed ?? true })
37+
XCTAssertEqual(crashedThreads?.count, 1)
38+
XCTAssertEqual(crashedThreads?.first?.name, "React Native")
3539
}
3640

3741
func testSanitizeReactDebugStacktrace() {
@@ -43,4 +47,12 @@ class SentrySwiftReactNativeCrashTests: XCTestCase {
4347
XCTAssertEqual(event?.threads?.last?.name, "React Native")
4448
XCTAssertEqual(event?.threads?.last?.stacktrace?.frames.first?.fileName, "/index.ios.bundle")
4549
}
50+
51+
func testInjectReactNativeStacktrace() {
52+
let crashJSON = testHelper.readIOSJSONCrashFile(name: "ReactNativeExample-report-with-stacktrace-and-address")!
53+
54+
let event = CrashReportConverter.convertReportToEvent(crashJSON)
55+
XCTAssertNotNil(event)
56+
XCTAssertEqual(event?.exceptions?.first?.thread?.stacktrace?.frames[8].platform, "javascript")
57+
}
4658
}

SentryTests/SentryTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@ class SentrySwiftTests: XCTestCase {
2929
XCTAssertNotNil(SentryClient.shared)
3030
}
3131

32+
func testSetExtraAndTags() {
33+
let client = SentrySwiftTestHelper.sentryMockClient
34+
client.tags = ["1": "2"]
35+
client.addTag("a", value: "b")
36+
XCTAssertEqual(client.tags["1"], "2")
37+
XCTAssertEqual(client.tags["a"], "b")
38+
39+
client.extra = ["1": "3"]
40+
client.addExtra("a", value: "c")
41+
XCTAssertEqual(client.extra["1"] as? String, "3")
42+
XCTAssertEqual(client.extra["a"] as? String, "c")
43+
}
44+
45+
func testRemoveSentryInternalExtras() {
46+
let event = SentrySwiftTestHelper.demoFatalEvent
47+
event.extra = ["1": "3"]
48+
event.addExtra("a", value: "c")
49+
event.addExtra("__sentry_stacktrace", value: "c")
50+
event.addExtra("__sentryasda", value: "c")
51+
52+
let serialized = event.serialized
53+
let extra = serialized["extra"] as! EventExtra
54+
XCTAssertEqual(extra.count, 2)
55+
XCTAssertEqual(extra["1"] as? String, "3")
56+
XCTAssertEqual(extra["a"] as? String, "c")
57+
XCTAssertNil(extra["__sentry_stacktrace"])
58+
}
59+
3260
#if swift(>=3.0)
3361

3462
func testImmutableCrashProperties() {

0 commit comments

Comments
 (0)