@@ -31,12 +31,12 @@ import WinSDK
31
31
// MARK: - Error Creation with CocoaError.Code
32
32
33
33
extension CocoaError {
34
- static func errorWithFilePath( _ code: CocoaError . Code , _ path: String , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
35
- CocoaError ( code, path: path, variant: variant, source: source, destination: destination)
34
+ static func errorWithFilePath( _ code: CocoaError . Code , _ path: String , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
35
+ CocoaError ( code, path: path, variant: variant, source: source, destination: destination, debugDescription : debugDescription )
36
36
}
37
37
38
- static func errorWithFilePath( _ code: CocoaError . Code , _ url: URL , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
39
- CocoaError ( code, url: url, variant: variant, source: source, destination: destination)
38
+ static func errorWithFilePath( _ code: CocoaError . Code , _ url: URL , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
39
+ CocoaError ( code, url: url, variant: variant, source: source, destination: destination, debugDescription : debugDescription )
40
40
}
41
41
}
42
42
@@ -81,21 +81,21 @@ extension POSIXError {
81
81
}
82
82
83
83
extension CocoaError {
84
- static func errorWithFilePath( _ pathOrURL: PathOrURL , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
84
+ static func errorWithFilePath( _ pathOrURL: PathOrURL , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
85
85
switch pathOrURL {
86
86
case . path( let path) :
87
- return Self . errorWithFilePath ( path, errno: errno, reading: reading, variant: variant, source: source, destination: destination)
87
+ return Self . errorWithFilePath ( path, errno: errno, reading: reading, variant: variant, source: source, destination: destination, debugDescription : debugDescription )
88
88
case . url( let url) :
89
- return Self . errorWithFilePath ( url, errno: errno, reading: reading, variant: variant, source: source, destination: destination)
89
+ return Self . errorWithFilePath ( url, errno: errno, reading: reading, variant: variant, source: source, destination: destination, debugDescription : debugDescription )
90
90
}
91
91
}
92
92
93
- static func errorWithFilePath( _ path: String , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
94
- CocoaError ( Code ( fileErrno: errno, reading: reading) , path: path, underlying: POSIXError ( errno: errno) , variant: variant, source: source, destination: destination)
93
+ static func errorWithFilePath( _ path: String , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
94
+ CocoaError ( Code ( fileErrno: errno, reading: reading) , path: path, underlying: POSIXError ( errno: errno) , variant: variant, source: source, destination: destination, debugDescription : debugDescription )
95
95
}
96
96
97
- static func errorWithFilePath( _ url: URL , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
98
- CocoaError ( Code ( fileErrno: errno, reading: reading) , url: url, underlying: POSIXError ( errno: errno) , variant: variant, source: source, destination: destination)
97
+ static func errorWithFilePath( _ url: URL , errno: Int32 , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
98
+ CocoaError ( Code ( fileErrno: errno, reading: reading) , url: url, underlying: POSIXError ( errno: errno) , variant: variant, source: source, destination: destination, debugDescription : debugDescription )
99
99
}
100
100
}
101
101
@@ -144,18 +144,18 @@ extension CocoaError.Code {
144
144
}
145
145
146
146
extension CocoaError {
147
- static func errorWithFilePath( _ path: PathOrURL , win32 dwError: DWORD , reading: Bool ) -> CocoaError {
147
+ static func errorWithFilePath( _ path: PathOrURL , win32 dwError: DWORD , reading: Bool , debugDescription : String ? = nil ) -> CocoaError {
148
148
switch path {
149
149
case let . path( path) :
150
- return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: path. isEmpty) , path: path, underlying: Win32Error ( dwError) )
150
+ return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: path. isEmpty) , path: path, underlying: Win32Error ( dwError) , debugDescription : debugDescription )
151
151
case let . url( url) :
152
152
let pathStr = url. withUnsafeFileSystemRepresentation { String ( cString: $0!) }
153
- return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: pathStr. isEmpty) , path: pathStr, url: url, underlying: Win32Error ( dwError) )
153
+ return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: pathStr. isEmpty) , path: pathStr, url: url, underlying: Win32Error ( dwError) , debugDescription : debugDescription )
154
154
}
155
155
}
156
156
157
- static func errorWithFilePath( _ path: String ? = nil , win32 dwError: DWORD , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil ) -> CocoaError {
158
- return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: path? . isEmpty) , path: path, underlying: Win32Error ( dwError) , variant: variant, source: source, destination: destination)
157
+ static func errorWithFilePath( _ path: String ? = nil , win32 dwError: DWORD , reading: Bool , variant: String ? = nil , source: String ? = nil , destination: String ? = nil , debugDescription : String ? = nil ) -> CocoaError {
158
+ return CocoaError ( . init( win32: dwError, reading: reading, emptyPath: path? . isEmpty) , path: path, underlying: Win32Error ( dwError) , variant: variant, source: source, destination: destination, debugDescription : debugDescription )
159
159
}
160
160
}
161
161
#endif
@@ -190,7 +190,8 @@ extension CocoaError {
190
190
underlying: ( some Error ) ? = Optional< CocoaError> . none,
191
191
variant: String ? = nil ,
192
192
source: String ? = nil ,
193
- destination: String ? = nil
193
+ destination: String ? = nil ,
194
+ debugDescription: String ? = nil
194
195
) {
195
196
self . init (
196
197
code,
@@ -199,7 +200,8 @@ extension CocoaError {
199
200
underlying: underlying,
200
201
variant: variant,
201
202
source: source,
202
- destination: destination
203
+ destination: destination,
204
+ debugDescription: debugDescription
203
205
)
204
206
}
205
207
@@ -209,7 +211,8 @@ extension CocoaError {
209
211
underlying: ( some Error ) ? = Optional< CocoaError> . none,
210
212
variant: String ? = nil ,
211
213
source: String ? = nil ,
212
- destination: String ? = nil
214
+ destination: String ? = nil ,
215
+ debugDescription: String ? = nil
213
216
) {
214
217
self . init (
215
218
code,
@@ -218,7 +221,8 @@ extension CocoaError {
218
221
underlying: underlying,
219
222
variant: variant,
220
223
source: source,
221
- destination: destination
224
+ destination: destination,
225
+ debugDescription: debugDescription
222
226
)
223
227
}
224
228
@@ -229,10 +233,11 @@ extension CocoaError {
229
233
underlying: ( some Error ) ? = Optional< CocoaError> . none,
230
234
variant: String ? = nil ,
231
235
source: String ? = nil ,
232
- destination: String ? = nil
236
+ destination: String ? = nil ,
237
+ debugDescription: String ? = nil
233
238
) {
234
239
#if FOUNDATION_FRAMEWORK
235
- self . init ( _uncheckedNSError: NSError . _cocoaError ( withCode: code. rawValue, path: path, url: url, underlying: underlying, variant: variant, source: source, destination: destination) as NSError )
240
+ self . init ( _uncheckedNSError: NSError . _cocoaError ( withCode: code. rawValue, path: path, url: url, underlying: underlying, variant: variant, source: source, destination: destination, debugDescription : debugDescription ) as NSError )
236
241
#else
237
242
var userInfo : [ String : Any ] = [ : ]
238
243
if let path {
@@ -253,6 +258,9 @@ extension CocoaError {
253
258
if let variant {
254
259
userInfo [ NSUserStringVariantErrorKey] = [ variant]
255
260
}
261
+ if let debugDescription {
262
+ userInfo [ NSDebugDescriptionErrorKey] = debugDescription
263
+ }
256
264
257
265
self . init ( code, userInfo: userInfo)
258
266
#endif
0 commit comments