Fix crash when sorting project references with missing PBXFileElement.name#1056
Fix crash when sorting project references with missing PBXFileElement.name#1056Ant-tree wants to merge 1 commit intotuist:mainfrom
Conversation
Refactor project reference sorting to handle nil values and use display names.
|
@dosubot could you review this PR? It fixes a crash in PBXProjEncoder when PBXFileElement.name is nil by falling back to path. |
|
The fix is correct and aligns with best practices: replacing the force-unwrapping of To ensure robustness, it's important to add or update tests that cover encoding projects where To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Fix crash when sorting project references with missing PBXFileElement.name
Resolves tuist/XcodeProj#1055
PBXProjEncoder.sortProjectReferencesforce-unwrapsPBXFileElement.namewhen sortingPBXProject.projectReferences. However,namecan legitimately benilin pbxproj files generated by Xcode (where the display label is derived frompath). This caused a runtime crash during encoding.Short description
When
PBXOutputSettings.projReferenceFormat == .xcode,PBXProjEncodersortsPBXProject.projectReferencesalphabetically by the referenced project name. If the referencedPBXFileElementhasname == nil, encoding crashes with:XcodeProj/PBXProjEncoder.swift:491: Fatal error: Unexpectedly found nil while unwrapping an Optional valueSolution
Use a stable "display name" for sorting that matches Xcode’s behavior:
namewhen presentpathwhennameisnil(and finally""as a last resort)This prevents crashes while keeping sorting deterministic.
Implementation
PBXProjEncoder.sortProjectReferencesto compute a display key usingname ?? path ?? ""Testing
PBXFileReferenceomitsname