Skip to content

Commit e5891bf

Browse files
committed
Add a property JSONError.path
1 parent 9b0be5b commit e5891bf

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
262262

263263
## Version History
264264

265+
#### Development
266+
267+
* Add convenience property `JSONError.path`.
268+
265269
#### v3.0.1 (2018-02-18)
266270

267271
* Fix Swift Package Manager support.

Sources/JSONError.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ public enum JSONError: Error, CustomStringConvertible {
5252
}
5353
}
5454

55+
/// The path that the error occurred at.
56+
public var path: String? {
57+
switch self {
58+
case .missingOrInvalidType(let path, expected: _, actual: _): return path
59+
case .outOfRangeInt64(let path, value: _, expected: _): return path
60+
case .outOfRangeDouble(let path, value: _, expected: _): return path
61+
case .outOfRangeDecimal(let path, value: _, expected: _): return path
62+
}
63+
}
64+
5565
fileprivate func withPrefix(_ prefix: String) -> JSONError {
5666
func prefixPath(_ path: String?, with prefix: String) -> String {
5767
guard let path = path, !path.isEmpty else { return prefix }

0 commit comments

Comments
 (0)