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
Maybe the same logic could be applied on the macOS shims. If this is the right direction I can send a PR with the fix. Another option would be to inspect exactly why XCTest is providing no command line arguments. But this would be much harder to do. Going the XCTest route or not I think crash is no good, so it should be protected somehow.
I think the correct behaviour in cases of undefined arguments:
I can't reproduce this, and it is not safe for us to assume the check that you've just written. If you have no command line arguments then the argument buffer will point to an empty array and we will not read from it. Seeing nil here is a serious thing we should continue to fatal error on.
Oh![]( The error first appeared at June 20th snapshot when it was still Process. I thought I tried a new snapshot. I did create the test but I was running the on the old snapshot directory. So I thought the error was still present, but it's not. Something fixed it, haha. Good)
Environment
macOS
Additional Detail from JIRA
md5: a3168b64f3cb1c06e8605f267e75f494
Issue Description:
If you try to access CommandLine.arguments or CommandLine.unsafeArgv inside an XCTest test case you get nice crash:
fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0 libswiftCore.dylib 0x000000010d6e0370 swift_reportError + 125
1 libswiftCore.dylib 0x000000010d6fcf90 _swift_stdlib_reportFatalError + 61
2 libswiftCore.dylib 0x000000010d6a9fe0 partial apply for thunk + 63
3 libswiftCore.dylib 0x000000010d503c50 specialized StaticString.withUTF8Buffer<A> (invoke : (UnsafeBufferPointer<UInt8>) -> A) -> A + 351
4 libswiftCore.dylib 0x000000010d672320 partial apply for (_fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> ()).(closure #2) + 158
5 libswiftCore.dylib 0x000000010d6a9fe0 partial apply for thunk + 63
6 libswiftCore.dylib 0x000000010d6afe20 partial apply for thunk + 14
7 libswiftCore.dylib 0x000000010d503c50 specialized StaticString.withUTF8Buffer<A> (invoke : (UnsafeBufferPointer<UInt8>) -> A) -> A + 351
8 libswiftCore.dylib 0x000000010d632b40 specialized _fatalErrorMessage(StaticString, StaticString, StaticString, UInt, flags : UInt32) -> () + 143
9 libswiftCore.dylib 0x000000010d671a00 specialized static Process._computeArguments() -> [String] + 1071
10 libswiftCore.dylib 0x000000010d624850 static Process.arguments.getter + 149
11 QuarkTests 0x000000010cc612a0 loadConfiguration(configurationFile : String) throws -> StructuredData + 755
12 QuarkTests 0x000000010cc606d0 configure<A where ...> (configurationFile : String, server : ConfigurableServer.Type, configure : (A) throws -> ResponderRepresentable) -> () + 169
13 QuarkTests 0x000000010cc5bc70 QuarkTests.testConfiguration() throws -> () + 495
14 QuarkTests 0x000000010cc5c7e0 @objc QuarkTests.testConfiguration() throws -> () + 50
15 CoreFoundation 0x00007fff85dde9e0 invoking_ + 140
16 CoreFoundation 0x00007fff85dde7e0 -[NSInvocation invoke] + 286
17 XCTest 0x0000000109c62d7e __24-[XCTestCase invokeTest]_block_invoke_2 + 481
18 XCTest 0x0000000109c9bc54 -[XCTestContext performInScope:] + 190
19 XCTest 0x0000000109c62c6c -[XCTestCase invokeTest] + 255
20 XCTest 0x0000000109c6340e -[XCTestCase performTest:] + 457
21 XCTest 0x0000000109c608ac -[XCTestSuite performTest:] + 447
22 XCTest 0x0000000109c608ac -[XCTestSuite performTest:] + 447
23 XCTest 0x0000000109c608ac -[XCTestSuite performTest:] + 447
24 XCTest 0x0000000109c74bc1 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 602
25 XCTest 0x0000000109c9cf0f _XCTestMain + 1050
26 xctest 0x0000000109c4374b <unavailable> + 0
27 libdyld.dylib 0x00007fff9772f5ac start + 1
For some reason _NSGetArgv is returning NULL here:
https://github.com/apple/swift/blob/fe932663a8b9119636d8e61711df733f3c9f703e/stdlib/public/stubs/CommandLine.cpp#L58
That behaviour only happens on Linux.
I protected from the crash by doing
Maybe the same logic could be applied on the macOS shims. If this is the right direction I can send a PR with the fix. Another option would be to inspect exactly why XCTest is providing no command line arguments. But this would be much harder to do. Going the XCTest route or not I think crash is no good, so it should be protected somehow.
I think the correct behaviour in cases of undefined arguments:
CommandLine.argc = 0
CommandLine.unsafeArgv = nil
CommandLine.arguments = []
@belkadan
The text was updated successfully, but these errors were encountered: