Skip to content

Warn when a target contains an unrecognized YAML key - #1661

Open
SwastikTripathi wants to merge 1 commit into
yonaskolb:masterfrom
SwastikTripathi:warn-unknown-target-keys
Open

SwastikTripathi wants to merge 1 commit into
yonaskolb:masterfrom
SwastikTripathi:warn-unknown-target-keys

Conversation

@SwastikTripathi

@SwastikTripathi SwastikTripathi commented Oct 25, 2026 •

Copy link
Copy Markdown

Motivation

Target.init(jsonDictionary:) silently ignores any top-level key it does not recognise. This creates a particularly nasty failure mode: writing resources: under a target (which is not a valid Target key, resources must be specified as source entries with buildPhase: resources) causes xcodegen generate to exit 0 with no warning, the project builds, but resource files are simply missing from the app bundle at runtime. The issue is only surfaced as a crash on launch (e.g. Could not locate configuration file: 'GoogleService-Info.plist').

Reported in #1645.

Changes

Target.validYAMLKeys, a new static Set<String> on Target listing every top-level YAML key that the parser recognises (from name through putResourcesBeforeSourcesBuildPhase, plus the template-related templates/templateAttributes keys that are consumed before Target.init is called).

SpecValidationError.ValidationError.unknownTargetKey, a new error case emitted for each unrecognised key.

SpecLoader.validateProjectDictionaryWarnings, extended to iterate over the raw project dictionary's targets and emit an unknownTargetKey warning for any key not in Target.validYAMLKeys. The generate command already calls this and prints each error as a warning before writing the project file.

Test, testSpecWarningValidation gains a new case that creates a target with resources: ["Resources"], calls validateProjectDictionaryWarnings, and asserts that the expected unknownTargetKey(target: "App", key: "resources") error is present.

Example output

warning: Target "App" has an unrecognized key "resources". This key will be ignored.
Check the XcodeGen documentation for valid target keys.

🤖 Generated with Claude Code

`Target.init(jsonDictionary:)` silently ignores any top-level key that it
does not recognise. This makes it very easy to misplace valid fields
(e.g. writing `resources:` instead of adding a source entry with
`buildPhase: resources`) and get a project that generates successfully but
is simply missing resources at runtime, with no diagnostic of any kind.

Add `Target.validYAMLKeys` — the exhaustive set of top-level keys that
Target parsing understands — and extend `validateProjectDictionaryWarnings`
to surface any key outside that set as a `SpecValidationError`. The warning
is printed by the `generate` command before the project file is written,
giving users an early signal that a key will be ignored.

Fixes yonaskolb#1645

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SwastikTripathi
SwastikTripathi force-pushed the warn-unknown-target-keys branch from 3191ad0 to 843d967 Compare October 25, 2026 05:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant