Skip to content

Commit 047b92d

Browse files
committed
PR feedback
1 parent c368663 commit 047b92d

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

Sources/Sentry/SentrySessionInternal.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (instancetype)initDefault:(NSString *)distinctId
3636
if (self = [super init]) {
3737
_sessionId = [NSUUID UUID];
3838
_started = [SentryDependencyContainer.sharedInstance.dateProvider date];
39-
_status = SentrySessionStatusOk;
39+
_status = kSentrySessionStatusOk;
4040
_sequence = 1;
4141
_errors = 0;
4242
_distinctId = distinctId;
@@ -79,13 +79,13 @@ - (nullable instancetype)initWithJSONObject:(NSDictionary *)jsonObject
7979
if (status == nil || ![status isKindOfClass:[NSString class]])
8080
return nil;
8181
if ([@"ok" isEqualToString:status]) {
82-
_status = SentrySessionStatusOk;
82+
_status = kSentrySessionStatusOk;
8383
} else if ([@"exited" isEqualToString:status]) {
84-
_status = SentrySessionStatusExited;
84+
_status = kSentrySessionStatusExited;
8585
} else if ([@"crashed" isEqualToString:status]) {
86-
_status = SentrySessionStatusCrashed;
86+
_status = kSentrySessionStatusCrashed;
8787
} else if ([@"abnormal" isEqualToString:status]) {
88-
_status = SentrySessionStatusAbnormal;
88+
_status = kSentrySessionStatusAbnormal;
8989
} else {
9090
return nil;
9191
}
@@ -151,7 +151,7 @@ - (void)endSessionExitedWithTimestamp:(NSDate *)timestamp
151151
{
152152
@synchronized(self) {
153153
[self changed];
154-
_status = SentrySessionStatusExited;
154+
_status = kSentrySessionStatusExited;
155155
[self endSessionWithTimestamp:timestamp];
156156
}
157157
}
@@ -160,7 +160,7 @@ - (void)endSessionCrashedWithTimestamp:(NSDate *)timestamp
160160
{
161161
@synchronized(self) {
162162
[self changed];
163-
_status = SentrySessionStatusCrashed;
163+
_status = kSentrySessionStatusCrashed;
164164
[self endSessionWithTimestamp:timestamp];
165165
}
166166
}
@@ -169,7 +169,7 @@ - (void)endSessionAbnormalWithTimestamp:(NSDate *)timestamp
169169
{
170170
@synchronized(self) {
171171
[self changed];
172-
_status = SentrySessionStatusAbnormal;
172+
_status = kSentrySessionStatusAbnormal;
173173
[self endSessionWithTimestamp:timestamp];
174174
}
175175
}
@@ -251,7 +251,7 @@ - (void)incrementErrors
251251
}
252252
}
253253

254-
- (id)copyWithZone:(nullable NSZone *)zone
254+
- (SentrySessionInternal *)safeCopyWithZone:(nullable NSZone *)zone
255255
{
256256
SentrySessionInternal *copy = [[[self class] allocWithZone:zone] init];
257257

Sources/Sentry/include/SentrySessionInternal.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ NS_ASSUME_NONNULL_BEGIN
66

77
NSString *nameForSentrySessionStatus(NSUInteger status);
88

9+
typedef NS_ENUM(NSUInteger, InternalSentrySessionStatus) {
10+
kSentrySessionStatusOk = 0,
11+
kSentrySessionStatusExited = 1,
12+
kSentrySessionStatusCrashed = 2,
13+
kSentrySessionStatusAbnormal = 3,
14+
};
15+
916
/**
1017
* The SDK uses SentrySession to inform Sentry about release and project associated project health.
1118
*/
12-
@interface SentrySessionInternal : NSObject <NSCopying>
19+
@interface SentrySessionInternal : NSObject
1320
SENTRY_NO_INIT
1421

1522
- (instancetype)initWithReleaseName:(NSString *)releaseName distinctId:(NSString *)distinctId;
@@ -31,7 +38,7 @@ SENTRY_NO_INIT
3138

3239
@property (nonatomic, readonly, strong) NSUUID *sessionId;
3340
@property (nonatomic, readonly, strong) NSDate *started;
34-
@property (nonatomic, readonly) NSUInteger status;
41+
@property (nonatomic, readonly) InternalSentrySessionStatus status;
3542
@property (nonatomic) NSUInteger errors;
3643
@property (nonatomic, readonly) NSUInteger sequence;
3744
@property (nonatomic, readonly, strong) NSString *distinctId;
@@ -53,6 +60,8 @@ SENTRY_NO_INIT
5360

5461
- (NSDictionary<NSString *, id> *)serialize;
5562

63+
- (SentrySessionInternal *)safeCopyWithZone:(nullable NSZone *)zone;
64+
5665
@end
5766

5867
NS_ASSUME_NONNULL_END

Sources/Swift/SentrySession.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
import Foundation
33

44
@objc @_spi(Private) public enum SentrySessionStatus: UInt {
5+
init(internalStatus: InternalSentrySessionStatus) {
6+
switch internalStatus {
7+
case .sentrySessionStatusOk:
8+
self = .ok
9+
case .sentrySessionStatusExited:
10+
self = .exited
11+
case .sentrySessionStatusCrashed:
12+
self = .crashed
13+
case .sentrySessionStatusAbnormal:
14+
fallthrough
15+
@unknown default:
16+
self = .abnormal
17+
}
18+
}
19+
520
case ok = 0
621
case exited = 1
722
case crashed = 2
@@ -69,7 +84,7 @@ import Foundation
6984
session.started
7085
}
7186
@objc public var status: SentrySessionStatus {
72-
SentrySessionStatus(rawValue: session.status) ?? .abnormal
87+
SentrySessionStatus(internalStatus: session.status)
7388
}
7489
@objc public var errors: UInt {
7590
get { session.errors }
@@ -118,10 +133,7 @@ import Foundation
118133
}
119134

120135
public func copy(with zone: NSZone? = nil) -> Any {
121-
let copy = session.copy(with: zone)
122-
guard let newSession = copy as? SentrySessionInternal else {
123-
return copy
124-
}
125-
return SentrySession(session: newSession)
136+
let copy = session.safeCopy(with: zone)
137+
return SentrySession(session: copy)
126138
}
127139
}

0 commit comments

Comments
 (0)