Skip to content

Commit

Permalink
feat: Support for fatalError, assert, precondition (#1596)
Browse files Browse the repository at this point in the history
The SDK was not able to retrieve the messages from Swifts fatalError, assert, or
precondition. This is fixed now by getting the message from the crashInfoMessage
of the binary image of libswiftCore.dylib.

Fixes GH-662

Co-authored-by: Dhiogo Brustolin <dhiogorb@gmail.com>
  • Loading branch information
philipphofmann and brustolin committed Jan 3, 2022
1 parent 168ccd5 commit fb25b59
Show file tree
Hide file tree
Showing 18 changed files with 26,054 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- feat: Support for fatalError, assert, precondition (#1596)
- feat: Include unfinished spans in transactions (#1592)
- build: Disable NSAssertions for Release Builds (#1545)

Expand Down
49 changes: 28 additions & 21 deletions Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="5CD-RQ-aBU">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="5CD-RQ-aBU">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="480-5y-FtF">
<rect key="frame" x="8" y="203" width="398" height="544.5"/>
<rect key="frame" x="8" y="188" width="398" height="574.5"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QJW-l9-sD6">
<rect key="frame" x="0.0" y="0.0" width="398" height="30"/>
Expand Down Expand Up @@ -64,68 +64,75 @@
<action selector="captureNSException:" destination="BYZ-38-t0r" eventType="touchUpInside" id="BT7-dZ-MrB"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cdR-H3-8fr">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UQw-od-fYk" userLabel="fatalError">
<rect key="frame" x="0.0" y="180" width="398" height="30"/>
<state key="normal" title="Capture Transaction"/>
<state key="normal" title="fatalError"/>
<connections>
<action selector="captureTransaction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="kff-pT-Uf4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8CV-WC-ffq">
<rect key="frame" x="0.0" y="210" width="398" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="testNavigationTransactionButton"/>
<state key="normal" title="Test Navigation Transaction"/>
<connections>
<segue destination="cay-7M-Gvd" kind="show" id="boD-GG-VVF"/>
<action selector="captureFatalError:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Uyy-8e-VRa"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="lgF-Uq-3Bb">
<rect key="frame" x="0.0" y="240" width="398" height="30"/>
<rect key="frame" x="0.0" y="210" width="398" height="30"/>
<state key="normal" title="crash"/>
<connections>
<action selector="crash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="imm-ZO-4Af"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="0Au-jS-aRl">
<rect key="frame" x="0.0" y="270" width="398" height="30"/>
<rect key="frame" x="0.0" y="240" width="398" height="30"/>
<state key="normal" title="OOM crash"/>
<connections>
<action selector="oomCrash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Oju-om-O6e"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xur-X2-ih4">
<rect key="frame" x="0.0" y="300" width="398" height="30"/>
<rect key="frame" x="0.0" y="270" width="398" height="30"/>
<state key="normal" title="async crash"/>
<connections>
<action selector="asyncCrash:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Mqi-sE-R7d"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LvU-yx-01i">
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cdR-H3-8fr">
<rect key="frame" x="0.0" y="300" width="398" height="30"/>
<state key="normal" title="Capture Transaction"/>
<connections>
<action selector="captureTransaction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="kff-pT-Uf4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8CV-WC-ffq">
<rect key="frame" x="0.0" y="330" width="398" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="testNavigationTransactionButton"/>
<state key="normal" title="Test Navigation Transaction"/>
<connections>
<segue destination="cay-7M-Gvd" kind="show" id="boD-GG-VVF"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="LvU-yx-01i">
<rect key="frame" x="0.0" y="360" width="398" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="showNibButton"/>
<state key="normal" title="Show Nib"/>
<connections>
<action selector="showNibController:" destination="BYZ-38-t0r" eventType="touchUpInside" id="E8m-GA-zvY"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="RjO-LN-eHj">
<rect key="frame" x="0.0" y="360" width="398" height="30"/>
<rect key="frame" x="0.0" y="390" width="398" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="showTableViewButton"/>
<state key="normal" title="Show TableView"/>
<connections>
<action selector="showTableViewController:" destination="BYZ-38-t0r" eventType="touchUpInside" id="u6U-9d-UMi"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ok0-hq-2kK">
<rect key="frame" x="0.0" y="390" width="398" height="30"/>
<rect key="frame" x="0.0" y="420" width="398" height="30"/>
<accessibility key="accessibilityConfiguration" identifier="showSplitViewButton"/>
<state key="normal" title="Show SplitView"/>
<connections>
<segue destination="DGj-BO-BQ5" kind="presentation" id="G2z-UO-upZ"/>
</connections>
</button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="UrL-kT-AJU">
<rect key="frame" x="0.0" y="420" width="398" height="124.5"/>
<rect key="frame" x="0.0" y="450" width="398" height="124.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DSN " textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="m3h-wb-Xfa">
<rect key="frame" x="8" y="32" width="382" height="20.5"/>
Expand Down
6 changes: 5 additions & 1 deletion Samples/iOS-Swift/iOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ViewController: UIViewController {
SentrySDK.addBreadcrumb(crumb: crumb)
}

@IBAction func captureMessage(_ sender: Any) {
@IBAction func captureMessage(_ sender: Any) {
let eventId = SentrySDK.capture(message: "Yeah captured a message")
// Returns eventId in case of successfull processed event
// otherwise nil
Expand Down Expand Up @@ -94,6 +94,10 @@ class ViewController: UIViewController {
SentrySDK.capture(exception: exception, scope: scope)
}

@IBAction func captureFatalError(_ sender: Any) {
fatalError("This is a fatal error. Oh no 😬.")
}

@IBAction func captureTransaction(_ sender: Any) {
let transaction = SentrySDK.startTransaction(name: "Some Transaction", operation: "Some Operation")
let span = transaction.startChild(operation: "user", description: "calls out")
Expand Down
2 changes: 1 addition & 1 deletion Samples/macOS-Swift/macOS-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ViewController: NSViewController {
SentrySDK.addBreadcrumb(crumb: crumb)
}

@IBAction func captureMessage(_ sender: Any) {
@IBAction func captureMessage(_ sender: Any) {
let eventId = SentrySDK.capture(message: "Yeah captured a message")
// Returns eventId in case of successfull processed event
// otherwise nil
Expand Down
4 changes: 4 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
7B30B67E26527894006B2752 /* SentryDisplayLinkWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B30B67D26527894006B2752 /* SentryDisplayLinkWrapper.m */; };
7B30B68026527C3C006B2752 /* SentryFramesTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B30B67F26527C3C006B2752 /* SentryFramesTrackerTests.swift */; };
7B30B68226527C55006B2752 /* TestDisplayLinkWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */; };
7B31C291277B04A000337126 /* SentryCrashPlatformSpecificDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B31C290277B04A000337126 /* SentryCrashPlatformSpecificDefines.h */; };
7B3398632459C14000BD9C96 /* SentryEnvelopeRateLimit.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B3398622459C14000BD9C96 /* SentryEnvelopeRateLimit.h */; };
7B3398652459C15200BD9C96 /* SentryEnvelopeRateLimit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3398642459C15200BD9C96 /* SentryEnvelopeRateLimit.m */; };
7B3398672459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3398662459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift */; };
Expand Down Expand Up @@ -816,6 +817,7 @@
7B30B67F26527C3C006B2752 /* SentryFramesTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFramesTrackerTests.swift; sourceTree = "<group>"; };
7B30B68126527C55006B2752 /* TestDisplayLinkWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDisplayLinkWrapper.swift; sourceTree = "<group>"; };
7B30B6882653AEA8006B2752 /* SentryFramesTracker+TestInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryFramesTracker+TestInit.h"; sourceTree = "<group>"; };
7B31C290277B04A000337126 /* SentryCrashPlatformSpecificDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SentryCrashPlatformSpecificDefines.h; sourceTree = "<group>"; };
7B3398622459C14000BD9C96 /* SentryEnvelopeRateLimit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEnvelopeRateLimit.h; path = include/SentryEnvelopeRateLimit.h; sourceTree = "<group>"; };
7B3398642459C15200BD9C96 /* SentryEnvelopeRateLimit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEnvelopeRateLimit.m; sourceTree = "<group>"; };
7B3398662459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEnvelopeRateLimitTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1720,6 +1722,7 @@
71F11CDEF5952DF5CC69AC74 /* SentryCrashUUIDConversion.h */,
A2475E1A25FB63D7007D9080 /* SentryHook.c */,
A2475E1625FB63AF007D9080 /* SentryHook.h */,
7B31C290277B04A000337126 /* SentryCrashPlatformSpecificDefines.h */,
);
path = Tools;
sourceTree = "<group>";
Expand Down Expand Up @@ -2386,6 +2389,7 @@
63FE715120DA4C1100CDBAE8 /* SentryCrashDebug.h in Headers */,
63FE70F520DA4C1000CDBAE8 /* SentryCrashMonitor_System.h in Headers */,
7BE3C7672445C0CA00A38442 /* SentryCurrentDate.h in Headers */,
7B31C291277B04A000337126 /* SentryCrashPlatformSpecificDefines.h in Headers */,
7B610D602512390E00B0B5D9 /* SentrySDK+Private.h in Headers */,
7BE3C76F2445C2F800A38442 /* SentryDefaultCurrentDateProvider.h in Headers */,
7B6C5EE0264E8E050010D138 /* SentryFramesTracker.h in Headers */,
Expand Down
Loading

0 comments on commit fb25b59

Please sign in to comment.