Skip to content

Commit f1cca38

Browse files
committed
Sentry NSError in Swift
1 parent 603fec8 commit f1cca38

File tree

9 files changed

+45
-97
lines changed

9 files changed

+45
-97
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
620078782D3906BF0022CB67 /* SentryCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620078772D3906BF0022CB67 /* SentryCodableTests.swift */; };
8383
620379DB2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h in Headers */ = {isa = PBXBuildFile; fileRef = 620379DA2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h */; };
8484
620379DD2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m in Sources */ = {isa = PBXBuildFile; fileRef = 620379DC2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m */; };
85-
620467AC2D3FFD230025F06C /* SentryNSErrorCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */; };
8685
6205B4A42CE73AA100744684 /* TestDebugImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D85790282976A69F00C6AC1F /* TestDebugImageProvider.swift */; };
8786
6205CF262D549D8A001E6049 /* SentryDateCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6205CF252D549D8A001E6049 /* SentryDateCodableTests.swift */; };
8887
621655662DB12A8900810504 /* SentryCrashMach-OTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 621655652DB12A8900810504 /* SentryCrashMach-OTests.m */; };
@@ -386,8 +385,6 @@
386385
7B3398652459C15200BD9C96 /* SentryEnvelopeRateLimit.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3398642459C15200BD9C96 /* SentryEnvelopeRateLimit.m */; };
387386
7B3398672459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3398662459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift */; };
388387
7B34721728086A9D0041F047 /* SentrySwizzleWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B34721628086A9D0041F047 /* SentrySwizzleWrapperTests.swift */; };
389-
7B3B473025D6CBFC00D01640 /* SentryNSError.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B3B472F25D6CBFC00D01640 /* SentryNSError.h */; settings = {ATTRIBUTES = (Public, ); }; };
390-
7B3B473825D6CC7E00D01640 /* SentryNSError.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B3B473725D6CC7E00D01640 /* SentryNSError.m */; };
391388
7B3B473E25D6CEA500D01640 /* SentryNSErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B3B473D25D6CEA500D01640 /* SentryNSErrorTests.swift */; };
392389
7B42C48027E08F33009B58C2 /* SentryDependencyContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B42C47F27E08F33009B58C2 /* SentryDependencyContainer.h */; settings = {ATTRIBUTES = (Private, ); }; };
393390
7B42C48227E08F4B009B58C2 /* SentryDependencyContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B42C48127E08F4B009B58C2 /* SentryDependencyContainer.m */; };
@@ -1062,8 +1059,9 @@
10621059
FA67DD182DDBD4EA00896B02 /* UIImageHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCED2DDBD4EA00896B02 /* UIImageHelper.swift */; };
10631060
FA67DD192DDBD4EA00896B02 /* SwizzleClassNameExclude.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA67DCD52DDBD4EA00896B02 /* SwizzleClassNameExclude.swift */; };
10641061
FA8A36182DEAA1EB0058D883 /* SentryThread+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */; };
1065-
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
1062+
FA8DEC2E2DF7F2D000C25374 /* SentryNSError.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8DEC2D2DF7F2D000C25374 /* SentryNSError.swift */; };
10661063
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */; };
1064+
FAEC273D2DF3933A00878871 /* NSData+Unzip.m in Sources */ = {isa = PBXBuildFile; fileRef = FAEC273C2DF3933200878871 /* NSData+Unzip.m */; };
10671065
/* End PBXBuildFile section */
10681066

10691067
/* Begin PBXContainerItemProxy section */
@@ -1223,7 +1221,6 @@
12231221
620078772D3906BF0022CB67 /* SentryCodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCodableTests.swift; sourceTree = "<group>"; };
12241222
620379DA2AFE1415005AC0C1 /* SentryBuildAppStartSpans.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryBuildAppStartSpans.h; path = include/SentryBuildAppStartSpans.h; sourceTree = "<group>"; };
12251223
620379DC2AFE1432005AC0C1 /* SentryBuildAppStartSpans.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBuildAppStartSpans.m; sourceTree = "<group>"; };
1226-
620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSErrorCodable.swift; sourceTree = "<group>"; };
12271224
6205CF252D549D8A001E6049 /* SentryDateCodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateCodableTests.swift; sourceTree = "<group>"; };
12281225
621655652DB12A8900810504 /* SentryCrashMach-OTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentryCrashMach-OTests.m"; sourceTree = "<group>"; };
12291226
621AE74A2C626C230012E730 /* SentryANRTrackerV2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryANRTrackerV2.h; path = include/SentryANRTrackerV2.h; sourceTree = "<group>"; };
@@ -1544,8 +1541,6 @@
15441541
7B3398662459C4AE00BD9C96 /* SentryEnvelopeRateLimitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEnvelopeRateLimitTests.swift; sourceTree = "<group>"; };
15451542
7B34721628086A9D0041F047 /* SentrySwizzleWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySwizzleWrapperTests.swift; sourceTree = "<group>"; };
15461543
7B3878E92490D90400EBDEA2 /* SentryClient+TestInit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryClient+TestInit.h"; sourceTree = "<group>"; };
1547-
7B3B472F25D6CBFC00D01640 /* SentryNSError.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryNSError.h; path = Public/SentryNSError.h; sourceTree = "<group>"; };
1548-
7B3B473725D6CC7E00D01640 /* SentryNSError.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryNSError.m; sourceTree = "<group>"; };
15491544
7B3B473D25D6CEA500D01640 /* SentryNSErrorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSErrorTests.swift; sourceTree = "<group>"; };
15501545
7B42C47F27E08F33009B58C2 /* SentryDependencyContainer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDependencyContainer.h; path = include/HybridPublic/SentryDependencyContainer.h; sourceTree = "<group>"; };
15511546
7B42C48127E08F4B009B58C2 /* SentryDependencyContainer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDependencyContainer.m; sourceTree = "<group>"; };
@@ -2304,6 +2299,7 @@
23042299
FA67DCEF2DDBD4EA00896B02 /* URLSessionTaskHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTaskHelper.swift; sourceTree = "<group>"; };
23052300
FA67DCF22DDBD4EA00896B02 /* SwiftDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDescriptor.swift; sourceTree = "<group>"; };
23062301
FA8A36172DEAA1EB0058D883 /* SentryThread+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryThread+Private.h"; path = "include/SentryThread+Private.h"; sourceTree = "<group>"; };
2302+
FA8DEC2D2DF7F2D000C25374 /* SentryNSError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSError.swift; sourceTree = "<group>"; };
23072303
FAEC270D2DF3526000878871 /* SentryUserFeedback.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUserFeedback.swift; sourceTree = "<group>"; };
23082304
FAEC273C2DF3933200878871 /* NSData+Unzip.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+Unzip.m"; sourceTree = "<group>"; };
23092305
FAEC273E2DF393E000878871 /* NSData+Unzip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+Unzip.h"; sourceTree = "<group>"; };
@@ -2408,7 +2404,6 @@
24082404
6293F5742D422A8A002BC3BD /* SentryStacktraceCodable.swift */,
24092405
62F70E922D4234B100634054 /* SentryMechanismMetaCodable.swift */,
24102406
62F70E942D423BCA00634054 /* SentryMechanismCodable.swift */,
2411-
620467AB2D3FFD1C0025F06C /* SentryNSErrorCodable.swift */,
24122407
620078712D38F00D0022CB67 /* SentryGeoCodable.swift */,
24132408
628094732D39584700B3F18B /* SentryUserCodable.swift */,
24142409
627C77882D50B6840055E966 /* SentryBreadcrumbCodable.swift */,
@@ -2537,8 +2532,6 @@
25372532
6334314020AD9AE40077E581 /* SentryMechanism.m */,
25382533
7BECF42126145C5D00D9826E /* SentryMechanismMeta.h */,
25392534
7BECF42726145CD900D9826E /* SentryMechanismMeta.m */,
2540-
7B3B472F25D6CBFC00D01640 /* SentryNSError.h */,
2541-
7B3B473725D6CC7E00D01640 /* SentryNSError.m */,
25422535
639FCFA61EBC80CC00778193 /* SentryFrame.h */,
25432536
639FCFA71EBC80CC00778193 /* SentryFrame.m */,
25442537
639FCFA21EBC809A00778193 /* SentryStacktrace.h */,
@@ -4102,6 +4095,7 @@
41024095
D856272A2A374A6800FB8062 /* Tools */,
41034096
D8B665BB2B95F5A100BD0E7B /* module.modulemap */,
41044097
FA4C32962DF7513F001D7B00 /* SentryExperimentalOptions.swift */,
4098+
FA8DEC2D2DF7F2D000C25374 /* SentryNSError.swift */,
41054099
);
41064100
path = Swift;
41074101
sourceTree = "<group>";
@@ -4716,7 +4710,6 @@
47164710
7BD4BD4727EB2A3D0071F4FF /* SentryDiscardedEvent.h in Headers */,
47174711
7BBD18972449DC1D00427C76 /* SentryRateLimits.h in Headers */,
47184712
844EDC76294144DB00C86F34 /* SentrySystemWrapper.h in Headers */,
4719-
7B3B473025D6CBFC00D01640 /* SentryNSError.h in Headers */,
47204713
630436101EC0600A00C4D3FA /* SentrySerializable.h in Headers */,
47214714
63FE70DD20DA4C1000CDBAE8 /* SentryCrashMonitor_Signal.h in Headers */,
47224715
63FE710320DA4C1000CDBAE8 /* SentryCrashMachineContext_Apple.h in Headers */,
@@ -5264,7 +5257,6 @@
52645257
7B7D873624864C9D00D2ECFF /* SentryCrashDefaultMachineContextWrapper.m in Sources */,
52655258
63FE712F20DA4C1100CDBAE8 /* SentryCrashSysCtl.c in Sources */,
52665259
62212B872D520CB00062C2FA /* SentryEventCodable.swift in Sources */,
5267-
7B3B473825D6CC7E00D01640 /* SentryNSError.m in Sources */,
52685260
621AE74D2C626C510012E730 /* SentryANRTrackerV2.m in Sources */,
52695261
84CFA4CA2C9DF884008DA5F4 /* SentryUserFeedbackWidget.swift in Sources */,
52705262
FAEC270E2DF3526000878871 /* SentryUserFeedback.swift in Sources */,
@@ -5468,6 +5460,7 @@
54685460
D8739D182BEEA33F007D2F66 /* SentryLevelHelper.m in Sources */,
54695461
63FE712720DA4C1000CDBAE8 /* SentryCrashThread.c in Sources */,
54705462
7B127B0F27CF6F4700A71ED2 /* SentryANRTrackingIntegration.m in Sources */,
5463+
FA8DEC2E2DF7F2D000C25374 /* SentryNSError.swift in Sources */,
54715464
62C316832B1F2EA1000D7031 /* SentryDelayedFramesTracker.m in Sources */,
54725465
D8BFE37329A3782F002E73F3 /* SentryTimeToDisplayTracker.m in Sources */,
54735466
15360CCF2432777500112302 /* SentrySessionTracker.m in Sources */,
@@ -5477,7 +5470,6 @@
54775470
F452437E2DE60B71003E8F50 /* SentryUseNSExceptionCallstackWrapper.m in Sources */,
54785471
63FE70D320DA4C1000CDBAE8 /* SentryCrashMonitor_AppState.c in Sources */,
54795472
849B8F9D2C6E906900148E1F /* SentryUserFeedbackWidgetConfiguration.swift in Sources */,
5480-
620467AC2D3FFD230025F06C /* SentryNSErrorCodable.swift in Sources */,
54815473
639FCFA51EBC809A00778193 /* SentryStacktrace.m in Sources */,
54825474
D84D2CC32C29AD120011AF8A /* SentrySessionReplay.swift in Sources */,
54835475
849B8F9B2C6E906900148E1F /* SentryUserFeedbackIntegrationDriver.swift in Sources */,

Sources/Sentry/Public/Sentry.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[];
3030
# import <Sentry/SentryMechanism.h>
3131
# import <Sentry/SentryMechanismMeta.h>
3232
# import <Sentry/SentryMessage.h>
33-
# import <Sentry/SentryNSError.h>
3433
# import <Sentry/SentryOptions.h>
3534
# import <Sentry/SentryReplayApi.h>
3635
# import <Sentry/SentryRequest.h>

Sources/Sentry/Public/SentryNSError.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

Sources/Sentry/SentryClient.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#import "SentryMeta.h"
2828
#import "SentryMsgPackSerializer.h"
2929
#import "SentryNSDictionarySanitize.h"
30-
#import "SentryNSError.h"
3130
#import "SentryOptions+Private.h"
3231
#import "SentryPropagationContext.h"
3332
#import "SentryRandom.h"

Sources/Sentry/SentryMechanism.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#import "NSMutableDictionary+Sentry.h"
33
#import "SentryMechanismMeta.h"
44
#import "SentryNSDictionarySanitize.h"
5-
#import "SentryNSError.h"
65

76
NS_ASSUME_NONNULL_BEGIN
87

Sources/Sentry/SentryMechanismMeta.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "SentryMechanismMeta.h"
22
#import "SentryNSDictionarySanitize.h"
3-
#import "SentryNSError.h"
3+
#import "SentrySwift.h"
44

55
NS_ASSUME_NONNULL_BEGIN
66

Sources/Sentry/SentryNSError.m

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/Swift/Protocol/Codable/SentryNSErrorCodable.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

Sources/Swift/SentryNSError.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Foundation
2+
3+
/// Sentry representation of an NSError to send to Sentry.
4+
@objcMembers
5+
open class SentryNSError: NSObject, SentrySerializable, Decodable {
6+
7+
/// The domain of an NSError.
8+
open var domain: String
9+
10+
/// The error code of an NSError.
11+
open var code: Int
12+
13+
/// Initializes SentryNSError and sets the domain and code.
14+
/// - Parameters:
15+
/// - domain: The domain of an NSError.
16+
/// - code: The error code of an NSError.
17+
public init(domain: String, code: Int) {
18+
self.domain = domain
19+
self.code = code
20+
super.init()
21+
}
22+
23+
open func serialize() -> [String: Any] {
24+
return ["domain": domain, "code": code]
25+
}
26+
27+
enum CodingKeys: String, CodingKey {
28+
case domain
29+
case code
30+
}
31+
32+
required convenience public init(from decoder: any Decoder) throws {
33+
let container = try decoder.container(keyedBy: CodingKeys.self)
34+
35+
let domain = try container.decode(String.self, forKey: .domain)
36+
let code = try container.decode(Int.self, forKey: .code)
37+
self.init(domain: domain, code: code)
38+
}
39+
}

0 commit comments

Comments
 (0)