@@ -127,13 +127,30 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
127
127
}
128
128
129
129
open var localizedDescription : String {
130
- let desc = userInfo [ NSLocalizedDescriptionKey] as? String
131
-
132
- return desc ?? " The operation could not be completed "
130
+ if let localizedDescription = userInfo [ NSLocalizedDescriptionKey] as? String {
131
+ return localizedDescription
132
+ } else {
133
+ // placeholder values
134
+ return " The operation could not be completed. " + " " + ( self . localizedFailureReason ?? " ( \( domain) error \( code) .) " )
135
+ }
133
136
}
134
137
135
138
open var localizedFailureReason : String ? {
136
- return userInfo [ NSLocalizedFailureReasonErrorKey] as? String
139
+
140
+ if let localizedFailureReason = userInfo [ NSLocalizedFailureReasonErrorKey] as? String {
141
+ return localizedFailureReason
142
+ } else {
143
+ switch domain {
144
+ case NSPOSIXErrorDomain:
145
+ return String ( cString: strerror ( Int32 ( code) ) , encoding: . ascii)
146
+ case NSCocoaErrorDomain:
147
+ return nil
148
+ case NSURLErrorDomain:
149
+ return nil
150
+ default :
151
+ return nil
152
+ }
153
+ }
137
154
}
138
155
139
156
open var localizedRecoverySuggestion : String ? {
@@ -164,7 +181,7 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
164
181
}
165
182
166
183
override open var description : String {
167
- return localizedDescription
184
+ return " Error Domain= \( domain ) Code= \( code ) \" \( localizedFailureReason ?? " (null) " ) \" "
168
185
}
169
186
170
187
// -- NSObject Overrides --
@@ -481,7 +498,7 @@ public protocol _BridgedNSError : __BridgedNSError, RawRepresentable, _Objective
481
498
482
499
/// Describes a bridged error that stores the underlying NSError, so
483
500
/// it can be queried.
484
- public protocol _BridgedStoredNSError : __BridgedNSError , _ObjectiveCBridgeableError , CustomNSError , Hashable {
501
+ public protocol _BridgedStoredNSError : __BridgedNSError , _ObjectiveCBridgeableError , CustomNSError , Hashable , CustomStringConvertible {
485
502
/// The type of an error code.
486
503
associatedtype Code : _ErrorCodeProtocol
487
504
@@ -499,6 +516,12 @@ public protocol _BridgedStoredNSError : __BridgedNSError, _ObjectiveCBridgeableE
499
516
init ( _nsError error: NSError )
500
517
}
501
518
519
+ public extension _BridgedStoredNSError {
520
+ var description : String {
521
+ return _nsError. description
522
+ }
523
+ }
524
+
502
525
/// Various helper implementations for _BridgedStoredNSError
503
526
extension _BridgedStoredNSError where Code: RawRepresentable , Code. RawValue: FixedWidthInteger {
504
527
public var code : Code {
0 commit comments