Skip to content

Commit 4549a39

Browse files
author
Anton Pogonets
committed
Make NSError.description closer to darwin
1 parent 992bb9e commit 4549a39

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Foundation/NSError.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
121121
open var localizedDescription: String {
122122
let desc = userInfo[NSLocalizedDescriptionKey] as? String
123123

124-
return desc ?? "The operation could not be completed"
124+
return desc ?? "The operation could not be completed. (\(domain) error \(code).)"
125125
}
126126

127127
open var localizedFailureReason: String? {
@@ -156,7 +156,14 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
156156
}
157157

158158
override open var description: String {
159-
return localizedDescription
159+
let localizedDescription = userInfo[NSLocalizedDescriptionKey] ?? "(null)"
160+
var result = "Error Domain=\(domain) Code=\(code) \"\(localizedDescription)\""
161+
162+
if let userInfo = _userInfo {
163+
result += " UserInfo=\(NSDictionary(dictionary: userInfo))"
164+
}
165+
166+
return result
160167
}
161168

162169
// -- NSObject Overrides --

0 commit comments

Comments
 (0)