Skip to content

Commit e2fb1f6

Browse files
committed
Make CBORError Equatable and remove unused cases
1 parent 5567a0a commit e2fb1f6

File tree

2 files changed

+1
-64
lines changed

2 files changed

+1
-64
lines changed

Sources/CBOR/CBORError.swift

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,20 @@
55
/// These errors provide detailed information about what went wrong during
66
/// CBOR processing operations, helping developers diagnose and fix issues
77
/// in their CBOR data or usage of the CBOR API.
8-
public enum CBORError: Error {
8+
public enum CBORError: Error, Equatable, Sendable {
99
/// The input data is not valid CBOR.
1010
///
1111
/// This error occurs when the decoder encounters data that doesn't conform to
1212
/// the CBOR specification (RFC 8949). This could be due to corrupted data,
1313
/// incomplete data, or data encoded with a different format entirely.
1414
case invalidCBOR
1515

16-
/// Expected a specific type but found another.
17-
///
18-
/// This error occurs when trying to decode a CBOR value as a specific type,
19-
/// but the actual type of the value doesn't match the expected type.
20-
/// - Parameters:
21-
/// - expected: The type that was expected (e.g., "String", "Int", "Array")
22-
/// - actual: The actual type that was found in the CBOR data
23-
case typeMismatch(expected: String, actual: String)
24-
25-
/// Array index out of bounds.
26-
///
27-
/// This error occurs when attempting to access an element in a CBOR array
28-
/// using an index that is outside the valid range for the array.
29-
/// - Parameters:
30-
/// - index: The requested index that was attempted to be accessed
31-
/// - count: The actual number of elements in the array (valid indices are 0..<count)
32-
case outOfBounds(index: Int, count: Int)
33-
34-
/// Required key missing from map.
35-
///
36-
/// This error occurs when trying to decode a CBOR map into a Swift struct or class,
37-
/// but a required key is not present in the map.
38-
/// - Parameter key: The name of the missing key
39-
case missingKey(String)
40-
41-
/// Value conversion failed.
42-
///
43-
/// This error occurs when a CBOR value cannot be converted to the requested Swift type,
44-
/// even though the CBOR type is compatible with the requested type.
45-
/// - Parameter message: A description of what went wrong during the conversion
46-
case valueConversionFailed(String)
47-
4816
/// Invalid UTF-8 string data.
4917
///
5018
/// This error occurs when decoding a CBOR text string that contains invalid UTF-8 sequences.
5119
/// All CBOR text strings must contain valid UTF-8 data according to the specification.
5220
case invalidUTF8
5321

54-
/// Integer overflow during encoding/decoding.
55-
///
56-
/// This error occurs when a CBOR integer value is too large to fit into the
57-
/// corresponding Swift integer type (e.g., trying to decode a UInt64.max into an Int).
58-
case integerOverflow
59-
60-
/// Tag value is not supported.
61-
///
62-
/// This error occurs when the decoder encounters a CBOR tag that is not supported
63-
/// by the current implementation.
64-
/// - Parameter tag: The unsupported tag number
65-
case unsupportedTag(UInt64)
66-
6722
/// Reached end of data while decoding.
6823
///
6924
/// This error occurs when the decoder unexpectedly reaches the end of the input data
@@ -106,20 +61,8 @@ extension CBORError: CustomStringConvertible {
10661
switch self {
10762
case .invalidCBOR:
10863
return "Invalid CBOR data: The input does not conform to the CBOR specification (RFC 8949)"
109-
case .typeMismatch(let expected, let actual):
110-
return "Type mismatch: expected \(expected), found \(actual)"
111-
case .outOfBounds(let index, let count):
112-
return "Array index out of bounds: attempted to access index \(index), but array only contains \(count) elements (valid indices are 0..<\(count))"
113-
case .missingKey(let key):
114-
return "Missing key: required key '\(key)' was not found in the CBOR map"
115-
case .valueConversionFailed(let message):
116-
return "Value conversion failed: \(message)"
11764
case .invalidUTF8:
11865
return "Invalid UTF-8 data: the CBOR text string contains invalid UTF-8 sequences"
119-
case .integerOverflow:
120-
return "Integer overflow: the CBOR integer value is too large for the target Swift integer type"
121-
case .unsupportedTag(let tag):
122-
return "Unsupported tag: tag \(tag) is not supported by this implementation"
12366
case .prematureEnd:
12467
return "Unexpected end of data: reached the end of input before completing the CBOR value"
12568
case .invalidInitialByte(let byte):

Tests/CBORTests/CBORErrorTests.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,7 @@ struct CBORErrorTests {
349349
// Test that all CBORError cases have meaningful descriptions
350350
let errors: [CBORError] = [
351351
.invalidCBOR,
352-
.typeMismatch(expected: "String", actual: "Int"),
353-
.outOfBounds(index: 5, count: 3),
354-
.missingKey("requiredKey"),
355-
.valueConversionFailed("Could not convert to Int"),
356352
.invalidUTF8,
357-
.integerOverflow,
358-
.unsupportedTag(123),
359353
.prematureEnd,
360354
.invalidInitialByte(0xFF),
361355
.lengthTooLarge(UInt64.max),

0 commit comments

Comments
 (0)