Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2872] Crash when FileManager's enumerate(at:...) tries to report an error #45466

Closed
tjw opened this issue Oct 5, 2016 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@tjw
Copy link
Contributor

tjw commented Oct 5, 2016

Previous ID SR-2872
Radar None
Original Reporter @tjw
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode 8.0 and 8.1b1.

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 9fe5e074fc987515d479e562a5bf2cb4

duplicates:

  • 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:

import Foundation

let u = 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-05 14:58:14.734 DirectoryEnumeratorObjC[65665:8668825] url: (null), error: Error Domain=NSCocoaErrorDomain Code=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).

@tjw
Copy link
Contributor Author

tjw commented Oct 5, 2016

Ah, apparently this exact issue is called out in the Xcode 8.1b2 release notes.

.. and this is a dup of SR-2690. Feel free to close if this doesn't add any extra info.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant