Skip to content

Commit 3da037d

Browse files
authored
fix: Remove unused decodable conformances (#6981)
1 parent d7dcd2c commit 3da037d

File tree

6 files changed

+6
-348
lines changed

6 files changed

+6
-348
lines changed

Sources/Swift/Protocol/SentryLog.swift

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public final class SentryLog: NSObject {
8383
}
8484
}
8585

86-
// MARK: - Internal Codable Support
87-
@_spi(Private) extension SentryLog: Codable {
86+
// MARK: - Internal Encodable Support
87+
@_spi(Private) extension SentryLog: Encodable {
8888
private enum CodingKeys: String, CodingKey {
8989
case timestamp
9090
case traceId = "trace_id"
@@ -94,27 +94,6 @@ public final class SentryLog: NSObject {
9494
case severityNumber = "severity_number"
9595
}
9696

97-
@_spi(Private) public convenience init(from decoder: any Decoder) throws {
98-
let container = try decoder.container(keyedBy: CodingKeys.self)
99-
100-
let timestamp = try container.decode(Date.self, forKey: .timestamp)
101-
let traceIdString = try container.decode(String.self, forKey: .traceId)
102-
let traceId = SentryId(uuidString: traceIdString)
103-
let level = try container.decode(Level.self, forKey: .level)
104-
let body = try container.decode(String.self, forKey: .body)
105-
let attributes = try container.decode([String: Attribute].self, forKey: .attributes)
106-
let severityNumber = try container.decodeIfPresent(Int.self, forKey: .severityNumber).map { NSNumber(value: $0) }
107-
108-
self.init(
109-
timestamp: timestamp,
110-
traceId: traceId,
111-
level: level,
112-
body: body,
113-
attributes: attributes,
114-
severityNumber: severityNumber
115-
)
116-
}
117-
11897
@_spi(Private) public func encode(to encoder: any Encoder) throws {
11998
var container = encoder.container(keyedBy: CodingKeys.self)
12099

Sources/Swift/Protocol/SentryLogAttribute.swift

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,13 @@ extension SentryLog {
6969
}
7070
}
7171

72-
// MARK: - Internal Codable Support
73-
@_spi(Private) extension SentryLog.Attribute: Codable {
72+
// MARK: - Internal Encodable Support
73+
@_spi(Private) extension SentryLog.Attribute: Encodable {
7474
private enum CodingKeys: String, CodingKey {
7575
case value
7676
case type
7777
}
7878

79-
@_spi(Private) public convenience init(from decoder: any Decoder) throws {
80-
let container = try decoder.container(keyedBy: CodingKeys.self)
81-
82-
let type = try container.decode(String.self, forKey: .type)
83-
84-
let value: Any
85-
switch type {
86-
case "string":
87-
value = try container.decode(String.self, forKey: .value)
88-
case "boolean":
89-
value = try container.decode(Bool.self, forKey: .value)
90-
case "integer":
91-
value = try container.decode(Int.self, forKey: .value)
92-
case "double":
93-
value = try container.decode(Double.self, forKey: .value)
94-
default:
95-
throw DecodingError.dataCorruptedError(forKey: .type, in: container, debugDescription: "Unknown type: \(type)")
96-
}
97-
98-
self.init(value: value)
99-
}
100-
10179
@_spi(Private) public func encode(to encoder: any Encoder) throws {
10280
var container = encoder.container(keyedBy: CodingKeys.self)
10381

Sources/Swift/Protocol/SentryLogLevel.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,8 @@ extension SentryLog {
7474
}
7575
}
7676

77-
// MARK: - Internal Codable Support
78-
@_spi(Private) extension SentryLog.Level: Codable {
79-
@_spi(Private) public init(from decoder: Decoder) throws {
80-
let container = try decoder.singleValueContainer()
81-
let stringValue = try container.decode(String.self)
82-
self = try .init(value: stringValue)
83-
}
77+
// MARK: - Internal Encodable Support
78+
@_spi(Private) extension SentryLog.Level: Encodable {
8479

8580
@_spi(Private) public func encode(to encoder: Encoder) throws {
8681
var container = encoder.singleValueContainer()

Tests/SentryTests/Protocol/SentryLogAttributeTests.swift

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -46,159 +46,6 @@ final class SentryLogAttributeTests: XCTestCase {
4646
XCTAssertEqual(doubleValue, 3.14159, accuracy: 0.00001)
4747
}
4848

49-
// MARK: - Decoding Tests
50-
51-
func testDecodeStringAttribute() throws {
52-
let json = Data("""
53-
{
54-
"type": "string",
55-
"value": "decoded value"
56-
}
57-
""".utf8)
58-
59-
let attribute = try XCTUnwrap(decodeFromJSONData(jsonData: json) as SentryLog.Attribute?)
60-
61-
XCTAssertEqual(attribute.type, "string")
62-
XCTAssertEqual(attribute.value as? String, "decoded value")
63-
}
64-
65-
func testDecodeBooleanAttribute() throws {
66-
let json = Data("""
67-
{
68-
"type": "boolean",
69-
"value": false
70-
}
71-
""".utf8)
72-
73-
let attribute = try XCTUnwrap(decodeFromJSONData(jsonData: json) as SentryLog.Attribute?)
74-
75-
XCTAssertEqual(attribute.type, "boolean")
76-
XCTAssertEqual(attribute.value as? Bool, false)
77-
}
78-
79-
func testDecodeIntegerAttribute() throws {
80-
let json = Data("""
81-
{
82-
"type": "integer",
83-
"value": 12345
84-
}
85-
""".utf8)
86-
87-
let attribute = try XCTUnwrap(decodeFromJSONData(jsonData: json) as SentryLog.Attribute?)
88-
89-
XCTAssertEqual(attribute.type, "integer")
90-
XCTAssertEqual(attribute.value as? Int, 12_345)
91-
}
92-
93-
func testDecodeDoubleAttribute() throws {
94-
let json = Data("""
95-
{
96-
"type": "double",
97-
"value": 2.71828
98-
}
99-
""".utf8)
100-
101-
let attribute = try XCTUnwrap(decodeFromJSONData(jsonData: json) as SentryLog.Attribute?)
102-
103-
XCTAssertEqual(attribute.type, "double")
104-
let doubleValue = try XCTUnwrap(attribute.value as? Double)
105-
XCTAssertEqual(doubleValue, 2.71828, accuracy: 0.00001)
106-
}
107-
108-
func testDecodeWithUnknownType_ReturnsNil() {
109-
let json = Data("""
110-
{
111-
"type": "unknown",
112-
"value": "test"
113-
}
114-
""".utf8)
115-
116-
let attribute = decodeFromJSONData(jsonData: json) as SentryLog.Attribute?
117-
118-
XCTAssertNil(attribute)
119-
}
120-
121-
func testDecodeWithMissingType_ReturnsNil() {
122-
let json = Data("""
123-
{
124-
"value": "test"
125-
}
126-
""".utf8)
127-
128-
let attribute = decodeFromJSONData(jsonData: json) as SentryLog.Attribute?
129-
130-
XCTAssertNil(attribute)
131-
}
132-
133-
func testDecodeWithMissingValue_ReturnsNil() {
134-
let json = Data("""
135-
{
136-
"type": "string"
137-
}
138-
""".utf8)
139-
140-
let attribute = decodeFromJSONData(jsonData: json) as SentryLog.Attribute?
141-
142-
XCTAssertNil(attribute)
143-
}
144-
145-
func testDecodeWithWrongValueType_ReturnsNil() {
146-
let json = Data("""
147-
{
148-
"type": "string",
149-
"value": 42
150-
}
151-
""".utf8)
152-
153-
let attribute = decodeFromJSONData(jsonData: json) as SentryLog.Attribute?
154-
155-
XCTAssertNil(attribute)
156-
}
157-
158-
// MARK: - Round-trip Tests
159-
160-
func testRoundTripStringAttribute() throws {
161-
let original = SentryLog.Attribute(string: "round trip test")
162-
163-
let data = try JSONEncoder().encode(original)
164-
let decoded = try XCTUnwrap(decodeFromJSONData(jsonData: data) as SentryLog.Attribute?)
165-
166-
XCTAssertEqual(decoded.type, original.type)
167-
XCTAssertEqual(decoded.value as? String, original.value as? String)
168-
}
169-
170-
func testRoundTripBooleanAttribute() throws {
171-
let original = SentryLog.Attribute(boolean: false)
172-
173-
let data = try JSONEncoder().encode(original)
174-
let decoded = try XCTUnwrap(decodeFromJSONData(jsonData: data) as SentryLog.Attribute?)
175-
176-
XCTAssertEqual(decoded.type, original.type)
177-
XCTAssertEqual(decoded.value as? Bool, original.value as? Bool)
178-
}
179-
180-
func testRoundTripIntegerAttribute() throws {
181-
let original = SentryLog.Attribute(integer: -999)
182-
183-
let data = try JSONEncoder().encode(original)
184-
let decoded = try XCTUnwrap(decodeFromJSONData(jsonData: data) as SentryLog.Attribute?)
185-
186-
XCTAssertEqual(decoded.type, original.type)
187-
XCTAssertEqual(decoded.value as? Int, original.value as? Int)
188-
}
189-
190-
func testRoundTripDoubleAttribute() throws {
191-
let original = SentryLog.Attribute(double: -123.456)
192-
193-
let data = try JSONEncoder().encode(original)
194-
let decoded = try XCTUnwrap(decodeFromJSONData(jsonData: data) as SentryLog.Attribute?)
195-
196-
XCTAssertEqual(decoded.type, original.type)
197-
let decodedValue = try XCTUnwrap(decoded.value as? Double)
198-
let originalValue = try XCTUnwrap(original.value as? Double)
199-
XCTAssertEqual(decodedValue, originalValue, accuracy: 0.00001)
200-
}
201-
20249
// MARK: - Initializer Tests
20350

20451
func testInitializer_StringValue() {

Tests/SentryTests/Protocol/SentryLogLevelTests.swift

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -59,80 +59,6 @@ final class SentryLogLevelTests: XCTestCase {
5959
XCTAssertEqual(jsonString, "\"fatal\"")
6060
}
6161

62-
// MARK: - Decoding Tests
63-
64-
func testDecodeTrace() throws {
65-
let jsonData = Data("\"trace\"".utf8)
66-
67-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
68-
69-
XCTAssertEqual(level, .trace)
70-
}
71-
72-
func testDecodeDebug() throws {
73-
let jsonData = Data("\"debug\"".utf8)
74-
75-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
76-
77-
XCTAssertEqual(level, .debug)
78-
}
79-
80-
func testDecodeInfo() throws {
81-
let jsonData = Data("\"info\"".utf8)
82-
83-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
84-
85-
XCTAssertEqual(level, .info)
86-
}
87-
88-
func testDecodeWarn() throws {
89-
let jsonData = Data("\"warn\"".utf8)
90-
91-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
92-
93-
XCTAssertEqual(level, .warn)
94-
}
95-
96-
func testDecodeError() throws {
97-
let jsonData = Data("\"error\"".utf8)
98-
99-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
100-
101-
XCTAssertEqual(level, .error)
102-
}
103-
104-
func testDecodeFatal() throws {
105-
let jsonData = Data("\"fatal\"".utf8)
106-
107-
let level = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?)
108-
109-
XCTAssertEqual(level, .fatal)
110-
}
111-
112-
// MARK: - Error Cases
113-
114-
func testDecodeCaseSensitive_ReturnsNil() {
115-
let jsonData = Data("\"TRACE\"".utf8)
116-
117-
let level = decodeFromJSONData(jsonData: jsonData) as SentryLog.Level?
118-
119-
XCTAssertNil(level)
120-
}
121-
122-
// MARK: - Round-trip Tests
123-
124-
func testRoundTrip() throws {
125-
let levels: [SentryLog.Level] = [.trace, .debug, .info, .warn, .error, .fatal]
126-
127-
for original in levels {
128-
129-
let data = try JSONEncoder().encode(original)
130-
let decoded = try XCTUnwrap(decodeFromJSONData(jsonData: data) as SentryLog.Level?)
131-
132-
XCTAssertEqual(decoded, original)
133-
}
134-
}
135-
13662
// MARK: - Array Tests
13763

13864
func testEncodeArrayOfLogLevels() throws {
@@ -144,22 +70,6 @@ final class SentryLogLevelTests: XCTestCase {
14470
XCTAssertEqual(jsonString, "[\"trace\",\"debug\",\"info\",\"warn\",\"error\",\"fatal\"]")
14571
}
14672

147-
func testDecodeArrayOfLogLevels() throws {
148-
let jsonData = Data("[\"trace\",\"debug\",\"info\",\"warn\",\"error\",\"fatal\"]".utf8)
149-
150-
let levels = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as [SentryLog.Level]?)
151-
152-
XCTAssertEqual(levels, [.trace, .debug, .info, .warn, .error, .fatal])
153-
}
154-
155-
func testDecodeArrayWithInvalidLevel_ReturnsNil() {
156-
let jsonData = Data("[\"trace\",\"invalid\",\"debug\"]".utf8)
157-
158-
let levels = decodeFromJSONData(jsonData: jsonData) as [SentryLog.Level]?
159-
160-
XCTAssertNil(levels)
161-
}
162-
16373
// MARK: - Dictionary Tests
16474

16575
func testEncodeLogLevelInDictionary() throws {
@@ -171,14 +81,6 @@ final class SentryLogLevelTests: XCTestCase {
17181
XCTAssertEqual(jsonString, "{\"level\":\"error\"}")
17282
}
17383

174-
func testDecodeLogLevelFromDictionary() throws {
175-
let jsonData = Data("{\"level\":\"warn\"}".utf8)
176-
177-
let dict = try XCTUnwrap(decodeFromJSONData(jsonData: jsonData) as [String: SentryLog.Level]?)
178-
179-
XCTAssertEqual(dict["level"], .warn)
180-
}
181-
18284
// MARK: - Value Property Tests
18385

18486
func testValuePropertyMatchesEncoding() throws {

0 commit comments

Comments
 (0)