-
Notifications
You must be signed in to change notification settings - Fork 8
/
Error.swift
40 lines (32 loc) · 1.36 KB
/
Error.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public extension JSON {
public enum Error: Swift.Error {
case missing(path: Path)
case typeMismatch(expected: Any.Type, actualValue: Any, path: Path)
case unexpected(value: Any?, path: Path)
case dataCorrupted(value: Any, description: String)
case other(description: String)
}
}
// MARK: - CustomStringConvertible
extension JSON.Error: CustomStringConvertible {
public var description: String {
switch self {
case let .missing(path: path):
return "missing(path: \(path))"
case let .typeMismatch(expected: expected, actualValue: actualValue, path: path):
return "typeMismatch(expected: \(expected), actualValue: \(actualValue), path: \(path))"
case let .unexpected(value: value, path: path):
return "unexpected(value: \(String(describing: value)), path: \(path))"
case let .dataCorrupted(value: value, description: description):
return "dataCorrupted(value: \(value), description: \(description))"
case let .other(description: description):
return "other(description: \(description))"
}
}
}
// MARK: - CustomDebugStringConvertible
extension JSON.Error: CustomDebugStringConvertible {
public var debugDescription: String {
return description
}
}