|
7 | 7 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
8 | 8 | //
|
9 | 9 |
|
10 |
| -//===----------------------------------------------------------------------===// |
11 |
| -// Errors |
12 |
| -//===----------------------------------------------------------------------===// |
13 |
| - |
14 |
| -// Adding the following extensions to EncodingError and DecodingError allows them to bridge to NSErrors implicitly. |
15 |
| - |
16 |
| -fileprivate let NSCodingPathErrorKey = "NSCodingPath" |
17 |
| -fileprivate let NSDebugDescriptionErrorKey = "NSDebugDescription" |
18 |
| - |
19 |
| -extension EncodingError : CustomNSError { |
20 |
| - public static var errorDomain: String = NSCocoaErrorDomain |
21 |
| - |
22 |
| - public var errorCode: Int { |
23 |
| - switch self { |
24 |
| - case .invalidValue(_, _): return CocoaError.coderInvalidValue.rawValue |
25 |
| - } |
26 |
| - } |
27 |
| - |
28 |
| - public var errorUserInfo: [String : Any] { |
29 |
| - let context: Context |
30 |
| - switch self { |
31 |
| - case .invalidValue(_, let c): context = c |
32 |
| - } |
33 |
| - |
34 |
| - return [NSCodingPathErrorKey: context.codingPath, |
35 |
| - NSDebugDescriptionErrorKey: context.debugDescription] |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -extension DecodingError : CustomNSError { |
40 |
| - public static var errorDomain: String = NSCocoaErrorDomain |
41 |
| - |
42 |
| - public var errorCode: Int { |
43 |
| - switch self { |
44 |
| - case .valueNotFound(_, _): fallthrough |
45 |
| - case .keyNotFound(_, _): |
46 |
| - return CocoaError.coderValueNotFound.rawValue |
47 |
| - |
48 |
| - case .typeMismatch(_, _): fallthrough |
49 |
| - case .dataCorrupted(_): |
50 |
| - return CocoaError.coderReadCorrupt.rawValue |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - public var errorUserInfo: [String : Any] { |
55 |
| - let context: Context |
56 |
| - switch self { |
57 |
| - case .typeMismatch(_, let c): context = c |
58 |
| - case .valueNotFound(_, let c): context = c |
59 |
| - case .keyNotFound(_, let c): context = c |
60 |
| - case .dataCorrupted(let c): context = c |
61 |
| - } |
62 |
| - |
63 |
| - return [NSCodingPathErrorKey: context.codingPath, |
64 |
| - NSDebugDescriptionErrorKey: context.debugDescription] |
65 |
| - } |
66 |
| -} |
67 |
| - |
68 | 10 | //===----------------------------------------------------------------------===//
|
69 | 11 | // Error Utilities
|
70 | 12 | //===----------------------------------------------------------------------===//
|
|
0 commit comments