** INTERNAL ERROR: Uncaught exception ** when building SwiftPM project

I'm seeing this error on CI Intel machines.
I'm aware it's vague mainly looking for ways to debug it or have more logs, any ideas?

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObjects:atIndexes:]: count of array (30) differs from count of index set (29)'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007ff80d0c86d6 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007ff80cbafc00 objc_exception_throw + 62
	2   CoreFoundation                      0x00007ff80d1ad40e -[__NSCFString characterAtIndex:].cold.1 + 0
	3   CoreFoundation                      0x00007ff80d0af471 -[NSMutableArray insertObjects:atIndexes:] + 1390
	4   IDEFoundation                       0x000000010e7ed8c2 __50-[IDEGroup insertGroupSubitems:atIndexes:context:]_block_invoke + 1864
	5   DVTFoundation                       0x000000010cfe5537 -[DVTModelObjectGraph performBlockCoalescingModelChanges:] + 48
	6   IDEFoundation                       0x000000010e7ed0d7 -[IDEGroup insertGroupSubitems:atIndexes:context:] + 297
	7   DVTFoundation                       0x000000010cf9a014 -[NSMutableArray(DVTFoundationClassAdditions) dvt_sortedInsertOfObjects:withComparator:] + 226
	8   IDESwiftPackageCore                 0x0000000119229526 $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC32registerDependencyFileReferences33_033DB97E8C2A552F3158921835EE9F98LL_27modelGraphSynchronizerTokenySayAA0abgH9ReferenceO010dependencyU0_AC16Reg	9   IDESwiftPackageCore                 0x000000011922caf5 $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC27dependencyPackagesDidUpdate33_033DB97E8C2A552F3158921835EE9F98LL8packages14graphHasErrors25revalidatedFilePathCaches27modelGraphSynchronizerToke	10  IDESwiftPackageCore                 0x00000001192240b8 $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC27packageGraphDidFinishAction_8duration6resulty7SwiftPM12SPMWorkspaceC0bgJ0O_SdAG0oebgJ16ResolutionResultOtYaFyAC05ModelG17SynchronizerToken33_033	11  IDESwiftPackageCore                 0x0000000119227eb1 $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC38disableWorkspaceContentSynchronization33_033DB97E8C2A552F3158921835EE9F98LL6duringyyAC27ModelGraphSynchronizerTokenAELLVXE_tFyyXEfU_TA + 17
	12  DVTFoundation                       0x000000010d1e48bd $sSo19DVTModelObjectGraphC13DVTFoundationE34performBlockCoalescingModelChangesyxxyXElFyyXEfU_ + 77
	13  DVTFoundation                       0x000000010d1aab6c $sSDySSSo8NSObjectCGIgo_ACIego_TR + 12
	14  DVTFoundation                       0x000000010d1e45ce $sIeg_IyB_TR + 14
	15  DVTFoundation                       0x000000010cfe5634 __58-[DVTModelObjectGraph performBlockCoalescingModelChanges:]_block_invoke + 121
	16  DVTFoundation                       0x000000010cfdcf6a -[DVTModelGraphTransactionScope performTransaction:] + 65
	17  DVTFoundation                       0x000000010cfe559a -[DVTModelObjectGraph performBlockCoalescingModelChanges:] + 147
	18  DVTFoundation                       0x000000010d1e508b $sSo19DVTModelObjectGraphC13DVTFoundationE34performBlockCoalescingModelChangesyxxyXElF + 331
	19  IDESwiftPackageCore                 0x0000000119219b89 $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC38disableWorkspaceContentSynchronization33_033DB97E8C2A552F3158921835EE9F98LL6duringyyAC27ModelGraphSynchronizerTokenAELLVXE_tF + 441
	20  IDESwiftPackageCore                 0x0000000119222e8d $s19IDESwiftPackageCore23IDESPMWorkspaceDelegateC27packageGraphDidFinishAction_8duration6resulty7SwiftPM12SPMWorkspaceC0bgJ0O_SdAG0oebgJ16ResolutionResultOtYaFTY4_ + 253
	21  IDESwiftPackageCore                 0x00000001191f73f1 $sIeAgH_ytIeAgHr_TRTATQ0_ + 1
	22  SwiftPM                             0x000000011d83f141 $s7SwiftPM12SPMWorkspaceC26packageGraphActionFinished33_918CA8CFEB8D3E06D2EEA2771EA5EA00LLyyAC07PackageE16ResolutionResultAELLVYaFTQ1_ + 1
	23  SwiftPM                             0x000000011d83e881 $s7SwiftPM12SPMWorkspaceC46processPackageGraphActionsInBackgroundIfNeeded33_918CA8CFEB8D3E06D2EEA2771EA5EA00LL010canProcessefG0yAC11AffirmativeO_tFyyYaYbcfU1_yyYacfU0_TQ1_ + 1
	24  SwiftPM                             0x000000011d898691 $s7Swif
tPM33SPMWorkspaceOrchestrationDelegateP27packageGraphDidFinishAction_8duration6resultyAA0C0C07PackagegJ0O_SdAA0cemgJ16ResolutionResultOtYaFTjTQ0_ + 1
	25  SwiftPM                             0x000000011d918b01 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRyt_Tg5TQ0_ + 1
	26  SwiftPM                             0x000000011d896ad1 $sxIeAgHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRs6ResultOySbsAA_pG_TG5TATQ0_ + 1
	27  libswift_Concurrency.dylib          0x00007ffd12cab441 _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
)

2 Likes

can relate. did you manage to find any resolution for this?

no, we ended up not using this

@mohamed-mosbah any chance this was related to using a Swift Registry?

I've hit the same exact stack trace and in my case the issue was that the Swift Registry had indexed the wrong Package.swift file. When using a registry on Artifactory and uploading a dependency with multiple Package.swift files in the repo, the wrong Package.swift file gets indexed resulting in this obscure error.

tldr: we had a few packages with inner “example usage“ packages in our registry service (for ex. GitHub - BarredEwe/Prefire: 🔥 A library based on Xcode Preview, for easy generation: Playbook view, Snapshot and Accessibility tests. SwiftUI and UIKit supported!) with other third party dependencies which resolver then grabs and filter at some point, but they still remains somehow in the process. solved the error in our case by manually grabbing all packages with such occurrences and removing unused manifests