Open jakepetroules opened 1 month ago
How about returning "."?
Is there a property with better semantics that currentDirectoryPath
can be deprecated in favor of?
Interesting, I just ran into this issue myself. I'm installing a Swift application from an RPM file, and that can remove the underlying directory for the app due to how installation is done. This causes the crash to happen sometimes, which is very interesting:
FoundationEssentials/SwiftFileManager.swift:289: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0 libswiftCore.so 0x00000000b61d8008 _swift_stdlib_reportFatalErrorInFile + 108
1 libswiftCore.so 0x00000000b5db25d8 <unavailable> + 1431000
Unfortunately I didn't get the full stack trace, but you get the idea.
Consider the following program:
This will crash:
...because
currentDirectoryPath
returns a non-optional String, and force unwraps the underlying optional string property, which returns nil if thegetcwd
function returns nil due to an error (one of these error conditions is that the current directory has been deleted, which can easily happen at runtime).Since we can't change the return type for source/bincompat, we should do something a bit more principled than crashing. Can we instead return an empty string in that case?