Thread 1: Can not set up _UISceneHostingView with a nil scene (NSInternalInconsistencyException)
- [X] I have read CONTRIBUTING and have done my best to follow them.
What did you do?
After switching to Xcode 16.0 RC (16A242), I gave my Quick/Nimble unit tests a run.
What did you expect to happen?
Unit tests normally run without any crashes.
What actually happened instead?
A couple of units are crashing due to not setting _UISceneHostingView in the PollAwait as it points out, but the issue is more likely related to threading.
Here are the logs:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can not set up _UISceneHostingView with a nil scene'
*** First throw call stack:
(
0 CoreFoundation 0x00000001804b70ec __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000018008ede8 objc_exception_throw + 72
2 Foundation 0x0000000180e73aa8 _userInfoForFileAndLine + 0
3 UIKitCore 0x0000000185ea759c -[_UISceneHostingView setPresentedScene:] + 568
4 UIKitCore 0x0000000185925dec -[_UISceneHostingController createSceneWithConfiguration:] + 188
5 UIKitCore 0x0000000185925c84 -[_UISceneHostingController initWithAdvancedConfiguration:] + 140
6 UIKitCore 0x0000000185925d14 -[_UISceneHostingController initWithProcessIdentity:sceneSpecification:] + 100
7 ShareSheet 0x000000019216423c -[SHSheetRemoteScene setupSceneHosting] + 220
8 ShareSheet 0x0000000192163f84 -[SHSheetRemoteScene activate] + 124
9 ShareSheet 0x00000001921a8168 -[SHSheetInteractor startSession] + 244
10 ShareSheet 0x00000001921a182c -[SHSheetPresenter initWithRouter:interactor:] + 160
11 ShareSheet 0x0000000192194bec +[SHSheetFactory createMainPresenterWithContext:] + 228
12 ShareSheet 0x000000019218cb3c -[UIActivityViewController _createMainPresenterIfNeeded] + 80
13 libdispatch.dylib 0x00000001801774ec _dispatch_call_block_and_release + 24
14 libdispatch.dylib 0x0000000180178de0 _dispatch_client_callout + 16
15 libdispatch.dylib 0x0000000180187c60 _dispatch_main_queue_drain + 1272
16 libdispatch.dylib 0x0000000180187758 _dispatch_main_queue_callback_4CF + 40
17 CoreFoundation 0x000000018041ae3c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
18 CoreFoundation 0x0000000180415534 __CFRunLoopRun + 1944
19 CoreFoundation 0x0000000180414960 CFRunLoopRunSpecific + 536
20 Foundation 0x0000000180f2af24 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 208
21 LawrencespringCoreTests 0x0000000123877f30 $s6Nimble19AwaitPromiseBuilderC4wait_14sourceLocationAA10PollResultOyxGSS_AA06SourceG0CtFyyXEfU1_ + 680
22 LawrencespringCoreTests 0x00000001237b975c $s6Nimble16ExceptionCaptureC8tryBlockyyyyXEF + 80
23 LawrencespringCoreTests 0x0000000123877a78 $s6Nimble19AwaitPromiseBuilderC4wait_14sourceLocationAA10PollResultOyxGSS_AA06SourceG0CtF + 320
24 LawrencespringCoreTests 0x0000000123879c54 $s6Nimble9pollBlock0B8Interval07timeoutD014sourceLocation6fnName10expressionAA10PollResultOySbGAA0a4TimeD0O_AlA06SourceG0CSSAA0K6StatusOyKctF + 432
25 LawrencespringCoreTests 0x000000012385b964 $s6Nimble4poll5style10matchStyle7matcher7timeoutAB6fnNameAA7MatcherVyxGAA011ExpectationE0O_AA010AsyncMatchE0OAjA0A12TimeIntervalOAPSStlFAA0J6ResultVAA10ExpressionVyxGcfU_ + 776
26 LawrencespringCoreTests 0x000000012385baf0 $s6Nimble4poll5style10matchStyle7matcher7timeoutAB6fnNameAA7MatcherVyxGAA011ExpectationE0O_AA010AsyncMatchE0OAjA0A12TimeIntervalOAPSStlFAA0J6ResultVAA10ExpressionVyxGcfU_TA + 96
27 LawrencespringCoreTests 0x000000012381aecc $s6Nimble7MatcherV9satisfiesyAA0B6ResultVAA10ExpressionVyxGKF + 100
28 LawrencespringCoreTests 0x00000001237c9684 $s6Nimble7execute___2to11description17captureExceptionsSb_AA14FailureMessageCtAA10ExpressionVyxG_AA16ExpectationStyleOAA7MatcherVyxGS2SSgSbtlF3runL_Sb_AGtylF + 568
29 LawrencespringCoreTests 0x00000001237c936c $s6Nimble7execute___2to11description17captureExceptionsSb_AA14FailureMessageCtAA10ExpressionVyxG_AA16ExpectationStyleOAA7MatcherVyxGS2SSgSbtlF + 652
30 LawrencespringCoreTests 0x000000012385ce6c $s6Nimble15SyncExpectationV12toEventually_7timeout12pollInterval11descriptionACyxGAA7MatcherVyxG_AA0a4TimeH0OAMSSSgtF + 652
31 LawrencespringCoreTests 0x000000011fb5eeac $s23LawrencespringCoreTests26NewScanQRCodeViewModelSpecC09test_scanfgH32_initialized_with_input_usecases33_C83F0D12D295EEE4BB7B0E0E829EBEBFLLyyFyyXEfU_yyXEfU0_yycfU0_ + 524
32 LawrencespringCoreTests 0x000000011fb8e29c $s23LawrencespringCoreTests26NewScanQRCodeViewModelSpecC09test_scanfgH32_initialized_with_input_usecases33_C83F0D12D295EEE4BB7B0E0E829EBEBFLLyyFyyXEfU_yyXEfU0_yycfU0_TA + 24
33 LawrencespringCoreTests 0x000000012389b3a0 $s5Quick7ExampleC3runyyF + 1800
34 LawrencespringCoreTests 0x00000001238a3e60 $s5Quick0A4SpecC17addInstanceMethod33_D86FDD85A286A7D5E390B606DFC86ECELL3for18classSelectorNames10ObjectiveC0Q0VAA7ExampleC_ShySSGztFZyACcfU_ + 84
35 LawrencespringCoreTests 0x00000001238a3eb0 $s5Quick0A4SpecCIegg_ACIeyBy_TR + 64
36 CoreFoundation 0x00000001804bdcc0 __invoking___ + 144
37 CoreFoundation 0x00000001804bac34 -[NSInvocation invoke] + 276
38 XCTestCore 0x00000001056faac4 +[XCTFailableInvocation invokeStandardConventionInvocation:completion:] + 64
39 XCTestCore 0x00000001056faa7c __90+[XCTFailableInvocation invokeInvocation:withTestMethodConvention:lastObservedErrorIssue:]_block_invoke_3 + 24
40 XCTestCore 0x00000001056fa2e8 __81+[XCTFailableInvocation invokeWithAsynchronousWait:lastObservedErrorIssue:block:]_block_invoke + 300
41 XCTestCore 0x00000001056e04d4 __49+[XCTSwiftErrorObservation observeErrorsInBlock:]_block_invoke + 28
42 libXCTestSwiftSupport.dylib 0x0000000104b46dfc $sIyB_Ieg_TR + 16
43 libXCTestSwiftSupport.dylib 0x0000000104b46c5c $sSo24XCTSwiftErrorObservationC6XCTestE14_observeErrors33_B0397D3B80CBC8D7FB9A5B33AB2A74B8LL2inAC8XCTIssueVSgycyyXE_tFZyyXEfU_ + 48
44 libXCTestSwiftSupport.dylib 0x0000000104b46fa8 $sSo24XCTSwiftErrorObservationC6XCTestE14_observeErrors33_B0397D3B80CBC8D7FB9A5B33AB2A74B8LL2inAC8XCTIssueVSgycyyXE_tFZyyXEfU_TA + 28
45 libswift_Concurrency.dylib 0x00000002444a2f5c $ss9TaskLocalC9withValue_9operation4file4lineqd__x_qd__yKXESSSutKlF + 128
46 libXCTestSwiftSupport.dylib 0x0000000104b46a98 $sSo24XCTSwiftErrorObservationC6XCTestE14_observeErrors33_B0397D3B80CBC8D7FB9A5B33AB2A74B8LL2inAC8XCTIssueVSgycyyXE_tFZ + 488
47 libXCTestSwiftSupport.dylib 0x0000000104b46d70 $sSo24XCTSwiftErrorObservationC6XCTestE14_observeErrors33_B0397D3B80CBC8D7FB9A5B33AB2A74B8LL2inAC8XCTIssueVSgycyyXE_tFZTo + 84
48 XCTestCore 0x00000001056e03d0 +[XCTSwiftErrorObservation observeErrorsInBlock:] + 160
49 XCTestCore 0x00000001056fa0c8 +[XCTFailableInvocation invokeWithAsynchronousWait:lastObservedErrorIssue:block:] + 184
50 XCTestCore 0x00000001056fa7cc +[XCTFailableInvocation invokeInvocation:withTestMethodConvention:lastObservedErrorIssue:] + 432
51 XCTestCore 0x00000001056fab50 +[XCTFailableInvocation invokeInvocation:lastObservedErrorIssue:] + 68
52 XCTestCore 0x00000001056b7268 __24-[XCTestCase invokeTest]_block_invoke.80 + 96
53 XCTestCore 0x00000001056bc6dc -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:] + 160
54 XCTestCore 0x00000001056b6df8 -[XCTestCase invokeTest] + 660
55 XCTestCore 0x00000001056b886c __26-[XCTestCase performTest:]_block_invoke.118 + 32
56 XCTestCore 0x00000001056bc6dc -[XCTestCase(XCTIssueHandling) _caughtUnhandledDeveloperExceptionPermittingControlFlowInterruptions:caughtInterruptionException:whileExecutingBlock:] + 160
57 XCTestCore 0x00000001056b82ac
libc++abi: terminating due to uncaught exception of type NSException
Environment
List the software versions you're using:
- Quick: 13.5.0
- Nimble: 3.0.0
- Xcode Version: Xcode 16.0 RC (16A242)
- Swift Version: 5.9
Yikes. Judging by your error message, this looks like a new check in SwiftUI that crashes if your UIHostingController isn't in a window?
At a guess, this might be solved by placing your UIHostingController in a new key window?
@TestState var window: UIWindow! // From Quick, this just nils out the window at the end of the test.
beforeEach {
// ...
// When you're setting up the UIHostingController.
window = UIWindow()
window.rootViewController = UIHostingController(rootView: TheView()) // or however you set up the UIHostingController.
window.makeKeyAndVisible()
// the rest of the setup.
}
// the rest of the tests.
If that doesn't help, then would you mind creating a small sample project that reproduces this issue?
Hello @younata,
Thank you for the answer. Unfortunately, I was not able to reproduce the issue on a test project, but let me give you some use case to prove why I believe the asynchronous implementation of Nimble needs a bit of adjustment.
The log that I provided was a crashed unit test for a ViewModel spec which doesn't have a UIViewController or a UIWindow. Anyway, I removed all of those units that were causing the crash, it seemed to work but now with some scheduler-related failures (which didn't occur in the previous Xcode) until the test process was completed and terminated, but then the same crash happened.
Another use case is that the crash would not happen if I run the unit tests independently, but only when I run the complete test module.
This issue is not random and it always happens in the mentioned patterns.
Hello @younata,
Thank you for the answer. Unfortunately, I was not able to reproduce the issue on a test project, but let me give you some use case to prove why I believe the asynchronous implementation of Nimble needs a bit of adjustment.
The log that I provided was a crashed unit test for a ViewModel spec which doesn't have a UIViewController or a UIWindow. Anyway, I removed all of those units that were causing the crash, it seemed to work but now with some scheduler-related failures (which didn't occur in the previous Xcode) until the test process was completed and terminated, but then the same crash happened.
Another use case is that the crash would not happen if I run the unit tests independently, but only when I run the complete test module.
This issue is not random and it always happens in the mentioned patterns.
Update:
- Running the test module on an iOS 17 simulator would not cause any crash, but it results in many scheduler-related failures throughout the module.
- The crash seems to happen only on iOS 18 simulators.
I've run into the same thing with testing, not related to Quick/Nimble. I found this X post and it helped me figure it out. https://x.com/Dimillian/status/1833448662090785204
I had some tests that were creating a UIActivityController. They weren't affected, but the test suite would fail on the next test that did a wait/expectation of some kind. So I would look through any tests that create UIActivityController and see if disabling those fixes your issues.
I've run into the same thing with testing, not related to Quick/Nimble. I found this X post and it helped me figure it out. https://x.com/Dimillian/status/1833448662090785204
I had some tests that were creating a UIActivityController. They weren't affected, but the test suite would fail on the next test that did a wait/expectation of some kind. So I would look through any tests that create UIActivityController and see if disabling those fixes your issues.
@joshwalker This was definitely the case, I have disabled the UIActivityController-related units and the process finishes flawlessly. Thank you so much!
@younata I apologise for bringing up this unrelated issue here, I hope you can also find it useful once you encountered it.
Having issues with this in xcode 16.1.0. Has a bug been filed with Apple for this?
Hi @makwanbarzan,
I’m encountering the same issue. Were you able to find a solution? Any suggestions or updates would be greatly appreciated.
Thanks in advance!
Any news about this issue? I'm facing the same problem here.
Getting the same issue. I have no UIActivityController on my project. Someone already found the solution?
Getting the same issue. I have no UIActivityController on my project. Someone already found the solution?
Did you solve it? I also have no UIActivityController.
