|
5 | 5 | /// These errors provide detailed information about what went wrong during
|
6 | 6 | /// CBOR processing operations, helping developers diagnose and fix issues
|
7 | 7 | /// in their CBOR data or usage of the CBOR API.
|
8 |
| -public enum CBORError: Error { |
| 8 | +public enum CBORError: Error, Equatable, Sendable { |
9 | 9 | /// The input data is not valid CBOR.
|
10 | 10 | ///
|
11 | 11 | /// This error occurs when the decoder encounters data that doesn't conform to
|
12 | 12 | /// the CBOR specification (RFC 8949). This could be due to corrupted data,
|
13 | 13 | /// incomplete data, or data encoded with a different format entirely.
|
14 | 14 | case invalidCBOR
|
15 | 15 |
|
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 |
| - |
48 | 16 | /// Invalid UTF-8 string data.
|
49 | 17 | ///
|
50 | 18 | /// This error occurs when decoding a CBOR text string that contains invalid UTF-8 sequences.
|
51 | 19 | /// All CBOR text strings must contain valid UTF-8 data according to the specification.
|
52 | 20 | case invalidUTF8
|
53 | 21 |
|
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 |
| - |
67 | 22 | /// Reached end of data while decoding.
|
68 | 23 | ///
|
69 | 24 | /// This error occurs when the decoder unexpectedly reaches the end of the input data
|
@@ -106,20 +61,8 @@ extension CBORError: CustomStringConvertible {
|
106 | 61 | switch self {
|
107 | 62 | case .invalidCBOR:
|
108 | 63 | 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)" |
117 | 64 | case .invalidUTF8:
|
118 | 65 | 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" |
123 | 66 | case .prematureEnd:
|
124 | 67 | return "Unexpected end of data: reached the end of input before completing the CBOR value"
|
125 | 68 | case .invalidInitialByte(let byte):
|
|
0 commit comments