From c09a4f75ff68fa939765e18a1137a05db4bf5136 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Mon, 12 Aug 2024 10:09:38 -0700 Subject: [PATCH] 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. --- Sources/Foundation/NSError.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/Foundation/NSError.swift b/Sources/Foundation/NSError.swift index af7fe0e54d..6f21d3a03d 100644 --- a/Sources/Foundation/NSError.swift +++ b/Sources/Foundation/NSError.swift @@ -182,7 +182,11 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding, @unchecked S } override open var description: String { - return "Error Domain=\(domain) Code=\(code) \"\(localizedFailureReason ?? "(null)")\"" + var result = "Error Domain=\(domain) Code=\(code) \"\(localizedFailureReason ?? "(null)")\"" + if !userInfo.isEmpty { + result += "UserInfo={\(userInfo.map { "\($0)=\($1)"}.joined(separator: ", "))}" + } + return result } // -- NSObject Overrides --