Skip to content

fix: make BuildOperationMetrics fields tolerant of missing keys#246

Merged
fortmarek merged 2 commits intoMobileNativeFoundation:masterfrom
fortmarek:fix/optional-build-operation-metrics-fields
Mar 3, 2026
Merged

fix: make BuildOperationMetrics fields tolerant of missing keys#246
fortmarek merged 2 commits intoMobileNativeFoundation:masterfrom
fortmarek:fix/optional-build-operation-metrics-fields

Conversation

@fortmarek
Copy link
Collaborator

@fortmarek fortmarek commented Mar 3, 2026

Related to tuist/tuist#9507

Summary

  • Xcode projects using betaFeature_enableExplicitModules produce xcactivitylog files where BuildOperationMetrics JSON may not contain all expected keys (e.g. clangCacheHits). This causes a DecodingError.keyNotFound when parsing these logs.
  • Add a custom Decodable initializer that uses decodeIfPresent with a default of 0 for each field, so parsing succeeds even when keys are absent.

Test plan

  • Added testBuildOperationMetricsWithMissingKeys — verifies decoding an empty JSON object {} succeeds with all fields defaulting to 0
  • Added testBuildOperationMetricsWithPartialKeys — verifies decoding JSON with only swift keys succeeds, with clang fields defaulting to 0
  • Existing tests continue to pass
Xcode projects using `betaFeature_enableExplicitModules` produce xcactivitylog files where BuildOperationMetrics may not contain all expected keys (e.g. clangCacheHits). This causes a DecodingError when parsing these logs. Add a custom Decodable initializer that uses decodeIfPresent with a default of 0 for each field, so parsing succeeds even when keys are absent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: fortmarek <marekfort@me.com>
@fortmarek fortmarek force-pushed the fix/optional-build-operation-metrics-fields branch from f508fae to 02abbf8 Compare March 3, 2026 14:55
The macos-26 runner has Xcode 26.x installed, not 16.4. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: fortmarek <marekfort@me.com>
@fortmarek fortmarek marked this pull request as ready for review March 3, 2026 15:16
@fortmarek fortmarek requested a review from pepicrft March 3, 2026 15:16
@fortmarek fortmarek merged commit 568a383 into MobileNativeFoundation:master Mar 3, 2026
4 checks passed
giginet added a commit to giginet/XCLogParser that referenced this pull request Mar 5, 2026
Replace the struct with optional fields approach with an enum that clearly distinguishes between Xcode 15.3-16.x (v15_3) and Xcode 26.4+ (v26_4) formats using associated values. This replaces the decodeIfPresent approach from MobileNativeFoundation#246 with a try-decode-fallback strategy that auto-detects the format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: giginet <giginet.net@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants