Skip to content

Commit c09a4f7

Browse files
committed
Include userInfo in Error descriptions
This more closely matches Darwin behavior, and makes it significantly easier to debug issues like "File was not found" which presently include no reference whatsoever to the actual file path.
1 parent 0d18916 commit c09a4f7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/Foundation/NSError.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding, @unchecked S
182182
}
183183

184184
override open var description: String {
185-
return "Error Domain=\(domain) Code=\(code) \"\(localizedFailureReason ?? "(null)")\""
185+
var result = "Error Domain=\(domain) Code=\(code) \"\(localizedFailureReason ?? "(null)")\""
186+
if !userInfo.isEmpty {
187+
result += "UserInfo={\(userInfo.map { "\($0)=\($1)"}.joined(separator: ", "))}"
188+
}
189+
return result
186190
}
187191

188192
// -- NSObject Overrides --

0 commit comments

Comments
 (0)