@@ -31,12 +31,12 @@ import WinSDK
3131// MARK: - Error Creation with CocoaError.Code
3232
3333extension 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 )
3636 }
3737
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 )
4040 }
4141}
4242
@@ -81,21 +81,21 @@ extension POSIXError {
8181}
8282
8383extension 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 {
8585 switch pathOrURL {
8686 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 )
8888 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 )
9090 }
9191 }
9292
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 )
9595 }
9696
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 )
9999 }
100100}
101101
@@ -144,18 +144,18 @@ extension CocoaError.Code {
144144}
145145
146146extension 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 {
148148 switch path {
149149 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 )
151151 case let . url( url) :
152152 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 )
154154 }
155155 }
156156
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 )
159159 }
160160}
161161#endif
@@ -190,7 +190,8 @@ extension CocoaError {
190190 underlying: ( some Error ) ? = Optional< CocoaError> . none,
191191 variant: String ? = nil ,
192192 source: String ? = nil ,
193- destination: String ? = nil
193+ destination: String ? = nil ,
194+ debugDescription: String ? = nil
194195 ) {
195196 self . init (
196197 code,
@@ -199,7 +200,8 @@ extension CocoaError {
199200 underlying: underlying,
200201 variant: variant,
201202 source: source,
202- destination: destination
203+ destination: destination,
204+ debugDescription: debugDescription
203205 )
204206 }
205207
@@ -209,7 +211,8 @@ extension CocoaError {
209211 underlying: ( some Error ) ? = Optional< CocoaError> . none,
210212 variant: String ? = nil ,
211213 source: String ? = nil ,
212- destination: String ? = nil
214+ destination: String ? = nil ,
215+ debugDescription: String ? = nil
213216 ) {
214217 self . init (
215218 code,
@@ -218,7 +221,8 @@ extension CocoaError {
218221 underlying: underlying,
219222 variant: variant,
220223 source: source,
221- destination: destination
224+ destination: destination,
225+ debugDescription: debugDescription
222226 )
223227 }
224228
@@ -229,10 +233,11 @@ extension CocoaError {
229233 underlying: ( some Error ) ? = Optional< CocoaError> . none,
230234 variant: String ? = nil ,
231235 source: String ? = nil ,
232- destination: String ? = nil
236+ destination: String ? = nil ,
237+ debugDescription: String ? = nil
233238 ) {
234239 #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 )
236241 #else
237242 var userInfo : [ String : Any ] = [ : ]
238243 if let path {
@@ -253,6 +258,9 @@ extension CocoaError {
253258 if let variant {
254259 userInfo [ NSUserStringVariantErrorKey] = [ variant]
255260 }
261+ if let debugDescription {
262+ userInfo [ NSDebugDescriptionErrorKey] = debugDescription
263+ }
256264
257265 self . init ( code, userInfo: userInfo)
258266 #endif
0 commit comments