You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-2690 Bad code generated for FileManager.enumerator(at:includingPropertiesForKeys:options:errorHandler:)
Issue Description:
When trying to use NSDirectoryEnumerator from Swift, if the error handler is non-nil and the enumeration encounters and error (like a missing directory), there is a crash:
importFoundationletu = URL(fileURLWithPath: "/tmp/", isDirectory: true)let d = FileManager.default.enumerator(at:u, includingPropertiesForKeys: nil, errorHandler: { (url:URL, error:Error) in return false})!print("d \(d)") // --> d <NSURLDirectoryEnumerator: 0x100a01940>
// Crashes, unless the error handler above is replaced with nil
for _ in d {}
With an equivalent ObjC version that logs the error you can see that `nil` is being passed for the `url` argument.
2016-10-0514:58:14.734DirectoryEnumeratorObjC[65665:8668825] url: (null), error: ErrorDomain=NSCocoaErrorDomainCode=260"The file “missing-path” couldn’t be opened because there is no such file."UserInfo={NSURL=file:///tmp/missing-path/, NSFilePath=/tmp/missing-path, NSUnderlyingError=0x100500720 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
So, it looks like the Swift overlay for this function should take a block of type (URL?, Error) -> Bool (or whatever is passing nil should cut it out and pass the URL that was the problem).
The text was updated successfully, but these errors were encountered:
Environment
Xcode 8.0 and 8.1b1.
Additional Detail from JIRA
md5: 9fe5e074fc987515d479e562a5bf2cb4
duplicates:
Issue Description:
When trying to use NSDirectoryEnumerator from Swift, if the error handler is non-nil and the enumeration encounters and error (like a missing directory), there is a crash:
With an equivalent ObjC version that logs the error you can see that `nil` is being passed for the `url` argument.
So, it looks like the Swift overlay for this function should take a block of type (URL?, Error) -> Bool (or whatever is passing nil should cut it out and pass the URL that was the problem).
The text was updated successfully, but these errors were encountered: