Skip to content

Commit ed67bc2

Browse files
authored
ref: Convert SentryCrash to swift (#6438)
1 parent 2c889f6 commit ed67bc2

19 files changed

+171
-38
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@
11161116
FAB007362E9EF8D3001C806A /* SentryUIViewControllerPerformanceTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */; };
11171117
FAB007432E9F47E8001C806A /* SessionTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007422E9F47E4001C806A /* SessionTracker.swift */; };
11181118
FAB007522E9FE2FF001C806A /* SentrySwizzleWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */; };
1119+
FAB007812EA01B98001C806A /* SentryCrashSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB0077B2EA01B95001C806A /* SentryCrashSwift.swift */; };
11191120
FAB359982E05D7E90083D5E3 /* SentryEventSwiftHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */; };
11201121
FAB3599A2E05D8080083D5E3 /* SentryEventSwiftHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */; };
11211122
FAB7BBA92E2577A6007301E1 /* SentryModels+Serializable.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */; };
@@ -2480,6 +2481,7 @@
24802481
FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIViewControllerPerformanceTracker.swift; sourceTree = "<group>"; };
24812482
FAB007422E9F47E4001C806A /* SessionTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTracker.swift; sourceTree = "<group>"; };
24822483
FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySwizzleWrapper.swift; sourceTree = "<group>"; };
2484+
FAB0077B2EA01B95001C806A /* SentryCrashSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCrashSwift.swift; sourceTree = "<group>"; };
24832485
FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEventSwiftHelper.h; path = include/SentryEventSwiftHelper.h; sourceTree = "<group>"; };
24842486
FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEventSwiftHelper.m; sourceTree = "<group>"; };
24852487
FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryModels+Serializable.h"; path = "include/SentryModels+Serializable.h"; sourceTree = "<group>"; };
@@ -4825,6 +4827,7 @@
48254827
F4FE9E062E6248BB0014FED5 /* SentryCrash */ = {
48264828
isa = PBXGroup;
48274829
children = (
4830+
FAB0077B2EA01B95001C806A /* SentryCrashSwift.swift */,
48284831
FA8AFCE72E8434A0007A0E18 /* SentryThreadInspector.swift */,
48294832
FAE579C62E7DE14400B710F9 /* SentryFrameRemover.swift */,
48304833
F4FE9E072E6248E40014FED5 /* SentryCrashWrapper.swift */,
@@ -5773,6 +5776,7 @@
57735776
844EDC77294144DB00C86F34 /* SentrySystemWrapper.mm in Sources */,
57745777
D451ED5F2D92ECDE00C9BEA8 /* SentryReplayFrame.swift in Sources */,
57755778
FAE579CC2E7DE14900B710F9 /* SentryFrameRemover.swift in Sources */,
5779+
FAB007812EA01B98001C806A /* SentryCrashSwift.swift in Sources */,
57765780
D49480D72DC23FE300A3B6E9 /* SentrySessionReplayDelegate.swift in Sources */,
57775781
FA67DCC12DDBD4C800896B02 /* SentrySDKLog+Configure.swift in Sources */,
57785782
6281C5722D3E4F12009D0978 /* DecodeArbitraryData.swift in Sources */,

Sources/Sentry/SentryCrashExceptionApplicationHelper.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
# import "SentryDependencyContainer.h"
99
# import "SentrySDK+Private.h"
1010
# import "SentrySDKInternal.h"
11+
# import "SentrySwift.h"
1112

1213
@implementation SentryCrashExceptionApplicationHelper
1314

1415
+ (void)reportException:(NSException *)exception
1516
{
16-
SentryCrash *crash = SentryDependencyContainer.sharedInstance.crashReporter;
17+
SentryCrashSwift *crash = SentryDependencyContainer.sharedInstance.crashReporter;
1718
if (nil != crash.uncaughtExceptionHandler && nil != exception) {
1819
crash.uncaughtExceptionHandler(exception);
1920
}

Sources/Sentry/SentryCrashInstallationReporter.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#import "SentryCrashReportSink.h"
55
#import "SentryDefines.h"
66
#import "SentryLogC.h"
7+
#import "SentrySwift.h"
8+
9+
@interface SentryCrashReportSink () <SentryCrashReportFilter>
10+
@end
711

812
NS_ASSUME_NONNULL_BEGIN
913

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#import "SentrySDK+Private.h"
1010
#import "SentrySwift.h"
1111
#import "SentrySystemWrapper.h"
12-
#import <SentryCrash.h>
1312
#import <SentryDebugImageProvider+HybridSDKs.h>
1413
#import <SentryDefaultAppStateManager.h>
1514
#import <SentryDefaultUIViewControllerPerformanceTracker.h>
@@ -242,10 +241,10 @@ - (SentryFileIOTracker *)fileIOTracker
242241
return SentryDependencies.fileIOTracker;
243242
}
244243

245-
- (SentryCrash *)crashReporter SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
244+
- (SentryCrashSwift *)crashReporter SENTRY_THREAD_SANITIZER_DOUBLE_CHECKED_LOCK
246245
{
247246
SENTRY_LAZY_INIT(_crashReporter,
248-
[[SentryCrash alloc] initWithBasePath:SentrySDKInternal.options.cacheDirectoryPath]);
247+
[[SentryCrashSwift alloc] initWith:SentrySDKInternal.options.cacheDirectoryPath]);
249248
}
250249

251250
- (id<SentryANRTracker>)getANRTracker:(NSTimeInterval)timeout

Sources/Sentry/SentryDependencyContainerSwiftHelper.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ + (SentryHub *)currentHub
3232
return SentrySDKInternal.currentHub;
3333
}
3434

35-
+ (SentryCrash *)crashReporter
35+
+ (nullable NSDictionary *)systemInfo
3636
{
37-
return SentryDependencyContainer.sharedInstance.crashReporter;
37+
return SentryDependencyContainer.sharedInstance.crashReporter.systemInfo;
38+
}
39+
40+
+ (BOOL)crashedLastLaunch
41+
{
42+
return SentryDependencyContainer.sharedInstance.crashReporter.crashedLastLaunch;
43+
}
44+
45+
+ (NSTimeInterval)activeDurationSinceLastCrash
46+
{
47+
return SentryDependencyContainer.sharedInstance.crashReporter.activeDurationSinceLastCrash;
3848
}
3949

4050
+ (nullable NSDate *)readTimestampLastInForeground

Sources/Sentry/SentryUncaughtNSExceptions.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# import "SentryCrash.h"
66
# import "SentryDependencyContainer.h"
7+
# import "SentrySwift.h"
78
# import "SentrySwizzle.h"
89
# import "SentryUncaughtNSExceptions.h"
910
# import <AppKit/NSApplication.h>
@@ -34,7 +35,7 @@ + (void)swizzleNSApplicationReportException
3435

3536
+ (void)capture:(nullable NSException *)exception
3637
{
37-
SentryCrash *crash = SentryDependencyContainer.sharedInstance.crashReporter;
38+
SentryCrashSwift *crash = SentryDependencyContainer.sharedInstance.crashReporter;
3839

3940
if (crash.uncaughtExceptionHandler == nil) {
4041
return;

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#endif
66

77
@class SentryBinaryImageCache;
8-
@class SentryCrash;
8+
@class SentryCrashSwift;
99
@class SentryCrashWrapper;
1010
@class SentryDebugImageProvider;
1111
@class SentryDispatchFactory;
@@ -107,7 +107,7 @@ SENTRY_NO_INIT
107107
@property (nonatomic, strong) id<SentryAppStateManager> appStateManager;
108108
@property (nonatomic, strong, readonly) SentryThreadInspector *threadInspector;
109109
@property (nonatomic, strong, readonly) SentryFileIOTracker *fileIOTracker;
110-
@property (nonatomic, strong) SentryCrash *crashReporter;
110+
@property (nonatomic, strong) SentryCrashSwift *crashReporter;
111111
@property (nonatomic, strong) SentryScopePersistentStore *scopePersistentStore;
112112
@property (nonatomic, strong) SentryDebugImageProvider *debugImageProvider;
113113

Sources/Sentry/include/SentryCrashReportFilter.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#import <Foundation/Foundation.h>
2929

30+
NS_ASSUME_NONNULL_BEGIN
31+
3032
/** Callback for filter operations.
3133
*
3234
* @param filteredReports The filtered reports (may be incomplete if "completed"
@@ -37,7 +39,7 @@
3739
* @param error Non-nil if an error occurred.
3840
*/
3941
typedef void (^SentryCrashReportFilterCompletion)(
40-
NSArray *filteredReports, BOOL completed, NSError *error);
42+
NSArray *_Nullable filteredReports, BOOL completed, NSError *_Nullable error);
4143

4244
/**
4345
* A filter receives a set of reports, possibly transforms them, and then
@@ -63,10 +65,12 @@ typedef void (^SentryCrashReportFilterCompletion)(
6365
* @param error The parameter to send as "error".
6466
*/
6567
static inline void
66-
sentrycrash_callCompletion(SentryCrashReportFilterCompletion onCompletion, NSArray *filteredReports,
67-
BOOL completed, NSError *error)
68+
sentrycrash_callCompletion(SentryCrashReportFilterCompletion onCompletion,
69+
NSArray *_Nullable filteredReports, BOOL completed, NSError *_Nullable error)
6870
{
6971
if (onCompletion) {
7072
onCompletion(filteredReports, completed, error);
7173
}
7274
}
75+
76+
NS_ASSUME_NONNULL_END

Sources/Sentry/include/SentryCrashReportWriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ typedef struct SentryCrashReportWriter {
224224

225225
typedef void (*SentryCrashReportWriteCallback)(const SentryCrashReportWriter *writer);
226226

227+
void sentry_crashCallback(const SentryCrashReportWriter *writer);
228+
227229
#ifdef __cplusplus
228230
}
229231
#endif

Sources/Sentry/include/SentryDependencyContainerSwiftHelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ NS_ASSUME_NONNULL_BEGIN
2929
+ (void)dispatchSyncOnMainQueue:(void (^)(void))block;
3030
+ (id<SentryObjCRuntimeWrapper>)objcRuntimeWrapper;
3131
+ (SentryHub *)currentHub;
32-
+ (SentryCrash *)crashReporter;
32+
+ (nullable NSDictionary *)systemInfo;
33+
+ (BOOL)crashedLastLaunch;
34+
+ (NSTimeInterval)activeDurationSinceLastCrash;
3335
+ (nullable NSDate *)readTimestampLastInForeground;
3436
+ (void)deleteTimestampLastInForeground;
3537
+ (void)storeTimestampLastInForeground:(NSDate *)timestamp;

0 commit comments

Comments
 (0)