Skip to content

Commit

Permalink
[WIP] React Native (#124)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
HazAT authored Feb 7, 2017
1 parent a5df1e7 commit 1b5ded9
Show file tree
Hide file tree
Showing 25 changed files with 5,762 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ Carthage/Checkouts
fastlane/test_output/
report.xml
.env
cobertura.xml
34 changes: 33 additions & 1 deletion Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
6320331F1E3A4BCE00E6318F /* Crash-missing-user.json in Resources */ = {isa = PBXBuildFile; fileRef = 632033101E3A4BCE00E6318F /* Crash-missing-user.json */; };
632496061DEC33EA0014A044 /* SentrySwizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632495C01DE70EFD0014A044 /* SentrySwizzle.swift */; };
6324960D1DEC33EE0014A044 /* SentrySwizzle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 632495C01DE70EFD0014A044 /* SentrySwizzle.swift */; };
6332A20B1E49AD1C0099D77A /* Sentry+UserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */; };
6332A20D1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
6332A20E1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
6332A20F1E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
6332A2101E49B28B0099D77A /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A20C1E49B28B0099D77A /* Log.swift */; };
6332A2121E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
6332A2131E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
6332A2141E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
6332A2151E49B3680099D77A /* Sentry+Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6332A2111E49B3680099D77A /* Sentry+Event.swift */; };
633C38171E01952E00A74C63 /* SentryReactNativeCrashTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 633C38161E01952E00A74C63 /* SentryReactNativeCrashTests.swift */; };
634EA0211DF85BF000FE83A9 /* Frame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 634EA0201DF85BF000FE83A9 /* Frame.swift */; };
6350F6631DCE1C6B00B6B596 /* SentryCrashProbeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6350F6621DCE1C6B00B6B596 /* SentryCrashProbeTests.swift */; };
Expand Down Expand Up @@ -403,6 +412,9 @@
6320330F1E3A4BCE00E6318F /* Crash-missing-crash.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Crash-missing-crash.json"; sourceTree = "<group>"; };
632033101E3A4BCE00E6318F /* Crash-missing-user.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "Crash-missing-user.json"; sourceTree = "<group>"; };
632495C01DE70EFD0014A044 /* SentrySwizzle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SentrySwizzle.swift; path = ios/SentrySwizzle.swift; sourceTree = "<group>"; };
6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Sentry+UserFeedback.swift"; path = "ios/Sentry+UserFeedback.swift"; sourceTree = "<group>"; };
6332A20C1E49B28B0099D77A /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
6332A2111E49B3680099D77A /* Sentry+Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Sentry+Event.swift"; sourceTree = "<group>"; };
633C38161E01952E00A74C63 /* SentryReactNativeCrashTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryReactNativeCrashTests.swift; sourceTree = "<group>"; };
634EA0201DF85BF000FE83A9 /* Frame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Frame.swift; sourceTree = "<group>"; };
6350F6621DCE1C6B00B6B596 /* SentryCrashProbeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryCrashProbeTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -565,6 +577,7 @@
036378281C225D5200644C01 /* Sentry.h */,
0363782B1C225D8300644C01 /* Sentry.swift */,
632495C01DE70EFD0014A044 /* SentrySwizzle.swift */,
6332A20C1E49B28B0099D77A /* Log.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -707,6 +720,16 @@
name = Network;
sourceTree = "<group>";
};
6332A2031E49ACF90099D77A /* Sentry */ = {
isa = PBXGroup;
children = (
8092F8E41CF2499600634F3F /* Sentry+Error.swift */,
6332A20A1E49AD1C0099D77A /* Sentry+UserFeedback.swift */,
6332A2111E49B3680099D77A /* Sentry+Event.swift */,
);
name = Sentry;
sourceTree = "<group>";
};
63CDAB411DD9D7F300B63921 /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -763,6 +786,7 @@
9B02CAB11CF5C1E8004F614C /* Extensions */ = {
isa = PBXGroup;
children = (
6332A2031E49ACF90099D77A /* Sentry */,
9B02CABA1CF5C25D004F614C /* Foundation */,
9B02CAB51CF5C1F9004F614C /* Swift */,
);
Expand All @@ -772,7 +796,6 @@
9B02CAB51CF5C1F9004F614C /* Swift */ = {
isa = PBXGroup;
children = (
8092F8E41CF2499600634F3F /* Sentry+Error.swift */,
9B02CAB61CF5C20F004F614C /* Dictionary+Extras.swift */,
);
name = Swift;
Expand Down Expand Up @@ -1254,12 +1277,14 @@
files = (
03817D801D301E1D005A674A /* Contexts.swift in Sources */,
03C7152C1CE4DB940080AE60 /* Breadcrumb.swift in Sources */,
6332A2141E49B3680099D77A /* Sentry+Event.swift in Sources */,
630271D71E377ECC0047DC3B /* MemoryAddress.swift in Sources */,
63571EEE1DFE99E6001924CD /* BinaryImage.swift in Sources */,
63D54E5E1E0A7D790005B07A /* RequestOperation.swift in Sources */,
9B02CAB91CF5C20F004F614C /* Dictionary+Extras.swift in Sources */,
6350F6751DCE2F0A00B6B596 /* CrashReportConverter.swift in Sources */,
03C715271CE4DB910080AE60 /* Event.swift in Sources */,
6332A20F1E49B28B0099D77A /* Log.swift in Sources */,
03C715241CE4DB8D0080AE60 /* Sentry.swift in Sources */,
8092F8EA1CF2594100634F3F /* Sentry+Error.swift in Sources */,
03C7152A1CE4DB910080AE60 /* EventSerializable.swift in Sources */,
Expand Down Expand Up @@ -1311,6 +1336,7 @@
files = (
03817D7E1D301E1D005A674A /* Contexts.swift in Sources */,
630271F11E3A368D0047DC3B /* QueueableRequestManager.swift in Sources */,
6332A20D1E49B28B0099D77A /* Log.swift in Sources */,
03A89AA11CAACA6F00D94E22 /* BreadcrumbStore.swift in Sources */,
03CFCEC31C612F5300999EB7 /* CrashHandler.swift in Sources */,
8092F8E51CF2499600634F3F /* Sentry+Error.swift in Sources */,
Expand All @@ -1329,6 +1355,7 @@
03C1E5A71C57192A004D68D8 /* EventOffline.swift in Sources */,
63571EEC1DFE99E6001924CD /* BinaryImage.swift in Sources */,
63CDAB8C1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
6332A2121E49B3680099D77A /* Sentry+Event.swift in Sources */,
630271C61E37701E0047DC3B /* Register.swift in Sources */,
03C1E26A1D4652180004A612 /* Thread.swift in Sources */,
03E3D1F81C3E1A2800F00547 /* DSN.swift in Sources */,
Expand Down Expand Up @@ -1365,6 +1392,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6332A20E1E49B28B0099D77A /* Log.swift in Sources */,
63571E8E1DFAAD41001924CD /* Frame.swift in Sources */,
03817D7F1D301E1D005A674A /* Contexts.swift in Sources */,
03C736E21C474715004428DF /* CrashHandler.swift in Sources */,
Expand Down Expand Up @@ -1395,8 +1423,10 @@
036378331C227C7900644C01 /* Event.swift in Sources */,
9BF8E80A1E3B5B6900A417AE /* Functions.swift in Sources */,
03A89AA21CAACA6F00D94E22 /* BreadcrumbStore.swift in Sources */,
6332A2131E49B3680099D77A /* Sentry+Event.swift in Sources */,
632496061DEC33EA0014A044 /* SentrySwizzle.swift in Sources */,
63CDAB8D1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
6332A20B1E49AD1C0099D77A /* Sentry+UserFeedback.swift in Sources */,
03D4D9FA1CA48FA800799CC9 /* Breadcrumb.swift in Sources */,
03E3D1D81C3E166800F00547 /* EventSerializable.swift in Sources */,
63CDAB871DDC51E400B63921 /* UserFeedbackTableViewController.swift in Sources */,
Expand Down Expand Up @@ -1430,6 +1460,7 @@
files = (
63CDAB3B1DD9D4AE00B63921 /* CrashHandler.swift in Sources */,
630271F41E3A368D0047DC3B /* QueueableRequestManager.swift in Sources */,
6332A2101E49B28B0099D77A /* Log.swift in Sources */,
63CDAB2D1DD9D49700B63921 /* Dictionary+Extras.swift in Sources */,
63CDAB371DD9D4A800B63921 /* Contexts.swift in Sources */,
63CDAB3D1DD9D4AE00B63921 /* CrashReportConverter.swift in Sources */,
Expand All @@ -1448,6 +1479,7 @@
63CDAB8F1DDCAAE700B63921 /* SentryEndpoint.swift in Sources */,
63571EEF1DFE99E6001924CD /* BinaryImage.swift in Sources */,
63CDAB301DD9D4A000B63921 /* EventProperties.swift in Sources */,
6332A2151E49B3680099D77A /* Sentry+Event.swift in Sources */,
630271C91E37701E0047DC3B /* Register.swift in Sources */,
63CDAB3A1DD9D4A800B63921 /* DebugMeta.swift in Sources */,
63CDAB281DD9D48500B63921 /* Sentry.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion SentryTests/SentryCrashProbeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SentrySwiftCrashProbeTests: XCTestCase {
let mechanism = event?.exceptions?.first?.mechanism
let posixSignal = mechanism?["posix_signal"] as? [String: AnyType]
let machException = mechanism?["mach_exception"] as? [String: AnyType]
XCTAssertEqual(mechanism?["relevant_address"] as? String, "0x9660f06")
XCTAssertEqual(mechanism?["relevant_address"] as? String, "0x109660f06")
XCTAssertEqual(posixSignal?["signal"] as? Int, 6)
XCTAssertEqual(machException?["exception"] as? Int, 10)
}
Expand Down
23 changes: 17 additions & 6 deletions SentryTests/SentryCrashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,28 @@ class SentrySwiftCrashTests: XCTestCase {
XCTAssertEqual(hexAddress?.asHex(), "0x3157e63d")
XCTAssertEqual(hexAddress?.asInt(), 827844157)

let hexAddress2 = MemoryAddress(nil)
XCTAssertNil(hexAddress2)
XCTAssertNil(hexAddress2?.asHex())

let hexAddress3 = MemoryAddress(String(
bytes: [0xD8, 0x00] as [UInt8],
encoding: String.Encoding.utf16BigEndian) as? AnyObject)
encoding: String.Encoding.utf16BigEndian))
XCTAssertNil(hexAddress3)

let hexAddress4 = MemoryAddress("ö" as? AnyObject)
let hexAddress4 = MemoryAddress("ö")
XCTAssertNil(hexAddress4)

let hexAddress5 = MemoryAddress("0xxx123")
XCTAssertNil(hexAddress5)

let hexAddress6 = MemoryAddress("0xA")
XCTAssertEqual(hexAddress6?.asInt(), 10)

let hexAddress7 = MemoryAddress("0x3157e63d")
XCTAssertEqual(hexAddress7?.asInt(), 827844157)

let hexAddress8 = MemoryAddress(MemoryAddress("0x1035AB510")?.asInt() as AnyObject?)
XCTAssertEqual(hexAddress8?.asInt(), 4351243536)

let hexAddress9 = MemoryAddress(MemoryAddress(4351243536 as AnyObject?)?.asHex())
XCTAssertEqual(hexAddress9?.asInt(), 4351243536)
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion SentryTests/SentryObjCTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ - (void)testThatThingsCompileBecauseSwiftToOjbCBridge {
@"some_things": @[@"green", @"red"],
@"foobar": @{@"foo": @"bar"}
};

[[SentryClient shared] addExtra:@"__sentry_stack" value:@"__sentry_stack"];
SentryClient *nilClient = nil;
[nilClient captureMessage:@"Some plain message from ObjC" level:SentrySeverityInfo];

Expand Down
12 changes: 12 additions & 0 deletions SentryTests/SentryReactNativeCrashTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class SentrySwiftReactNativeCrashTests: XCTestCase {
XCTAssertNotNil(event)
XCTAssertEqual(event?.threads?.last?.name, "React Native")
XCTAssertEqual(event?.threads?.last?.stacktrace?.frames.first?.fileName, "/main.jsbundle")

let crashedThreads = event?.threads?.filter({ $0.crashed ?? true })
XCTAssertEqual(crashedThreads?.count, 1)
XCTAssertEqual(crashedThreads?.first?.name, "React Native")
}

func testSanitizeReactDebugStacktrace() {
Expand All @@ -43,4 +47,12 @@ class SentrySwiftReactNativeCrashTests: XCTestCase {
XCTAssertEqual(event?.threads?.last?.name, "React Native")
XCTAssertEqual(event?.threads?.last?.stacktrace?.frames.first?.fileName, "/index.ios.bundle")
}

func testInjectReactNativeStacktrace() {
let crashJSON = testHelper.readIOSJSONCrashFile(name: "ReactNativeExample-report-with-stacktrace-and-address")!

let event = CrashReportConverter.convertReportToEvent(crashJSON)
XCTAssertNotNil(event)
XCTAssertEqual(event?.exceptions?.first?.thread?.stacktrace?.frames[8].platform, "javascript")
}
}
28 changes: 28 additions & 0 deletions SentryTests/SentryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ class SentrySwiftTests: XCTestCase {
XCTAssertNotNil(SentryClient.shared)
}

func testSetExtraAndTags() {
let client = SentrySwiftTestHelper.sentryMockClient
client.tags = ["1": "2"]
client.addTag("a", value: "b")
XCTAssertEqual(client.tags["1"], "2")
XCTAssertEqual(client.tags["a"], "b")

client.extra = ["1": "3"]
client.addExtra("a", value: "c")
XCTAssertEqual(client.extra["1"] as? String, "3")
XCTAssertEqual(client.extra["a"] as? String, "c")
}

func testRemoveSentryInternalExtras() {
let event = SentrySwiftTestHelper.demoFatalEvent
event.extra = ["1": "3"]
event.addExtra("a", value: "c")
event.addExtra("__sentry_stacktrace", value: "c")
event.addExtra("__sentryasda", value: "c")

let serialized = event.serialized
let extra = serialized["extra"] as! EventExtra
XCTAssertEqual(extra.count, 2)
XCTAssertEqual(extra["1"] as? String, "3")
XCTAssertEqual(extra["a"] as? String, "c")
XCTAssertNil(extra["__sentry_stacktrace"])
}

#if swift(>=3.0)

func testImmutableCrashProperties() {
Expand Down
Loading

0 comments on commit 1b5ded9

Please sign in to comment.