Skip to content

Commit 8f38678

Browse files
author
Itai Ferber
committed
Expose underlyingError on coding errors
Some errors are caused by others — this allows us to expose the underlying problem.
1 parent ffa5898 commit 8f38678

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

stdlib/public/core/Codable.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,13 +2026,18 @@ public enum EncodingError : Error {
20262026
/// A description of what went wrong, for debugging purposes.
20272027
public let debugDescription: String
20282028

2029+
/// The underlying error which caused this error, if any.
2030+
public let underlyingError: Error?
2031+
20292032
/// Initializes `self` with the given path of `CodingKey`s and a description of what went wrong.
20302033
///
20312034
/// - parameter codingPath: The path of `CodingKey`s taken to get to the point of the failing encode call.
20322035
/// - parameter debugDescription: A description of what went wrong, for debugging purposes.
2033-
public init(codingPath: [CodingKey?], debugDescription: String) {
2036+
/// - parameter underlyingError: The underlying error which caused this error, if any.
2037+
public init(codingPath: [CodingKey?], debugDescription: String, underlyingError: Error? = nil) {
20342038
self.codingPath = codingPath
20352039
self.debugDescription = debugDescription
2040+
self.underlyingError = underlyingError
20362041
}
20372042
}
20382043

@@ -2052,13 +2057,18 @@ public enum DecodingError : Error {
20522057
/// A description of what went wrong, for debugging purposes.
20532058
public let debugDescription: String
20542059

2060+
/// The underlying error which caused this error, if any.
2061+
public let underlyingError: Error?
2062+
20552063
/// Initializes `self` with the given path of `CodingKey`s and a description of what went wrong.
20562064
///
20572065
/// - parameter codingPath: The path of `CodingKey`s taken to get to the point of the failing decode call.
20582066
/// - parameter debugDescription: A description of what went wrong, for debugging purposes.
2059-
public init(codingPath: [CodingKey?], debugDescription: String) {
2067+
/// - parameter underlyingError: The underlying error which caused this error, if any.
2068+
public init(codingPath: [CodingKey?], debugDescription: String, underlyingError: Error? = nil) {
20602069
self.codingPath = codingPath
20612070
self.debugDescription = debugDescription
2071+
self.underlyingError = underlyingError
20622072
}
20632073
}
20642074

0 commit comments

Comments
 (0)