Skip to content

Conversation

@pepicrft
Copy link
Contributor

Summary

This PR adds support for the strictMemorySafety SwiftSetting introduced in Swift Package Manager 6.2 (SE-0458) and significantly improves error handling for malformed package settings.

Problem

When using Swift 6.2 with packages that enable strict memory safety checking via .strictMemorySafety(), Tuist was failing with cryptic decoding errors:

keyNotFound(CodingKeys(stringValue: "name", intValue: nil), Swift.DecodingError.Context(...))

This happened because:

  1. XcodeGraph didn't support the new strictMemorySafety setting type
  2. When the Kind decoder failed, it fell back to legacy format
  3. The legacy format decoder threw unhelpful errors

Changes

1. Add strictMemorySafety Support

  • Added strictMemorySafety case to SettingName enum
  • Added strictMemorySafety(String) case to Kind enum
  • Added decoder handler for strictMemorySafety in switch statement
  • Added encoder handler for strictMemorySafety in switch statement

2. Improve Error Handling

Introduced SettingDecodingError that provides actionable diagnostics:

Before:

keyNotFound(CodingKeys(stringValue: "name", intValue: nil), ...)

After:

Failed to decode target build setting at 'targets.Index 3.settings.Index 0'.
Expected either 'kind' (Xcode 14+ format) or 'name' (legacy format) key, but neither was found.
Tool: swift
Available keys: tool, condition, kind

This usually indicates a malformed Package.swift manifest or an unsupported Swift Package Manager version.

Testing

  • ✅ Build passes: swift build (3.53s)
  • ✅ All existing tests pass
  • ✅ Decoding now supports Swift 6.2 packages with strictMemorySafety

Context

  • Swift 6.2 introduced strictMemorySafety setting per SE-0458
  • This setting enables compiler checks for memory safety violations
  • Packages using this setting were causing Tuist to fail during manifest parsing

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

…or handling

This commit adds two important improvements to PackageInfo decoding:

1. **Add strictMemorySafety support**: Adds the strictMemorySafety setting introduced in Swift Package Manager 6.2 (SE-0458). This setting enables strict memory safety checking and was causing decoding failures when packages used this new setting.

2. **Improve error handling**: Wraps legacy format decoding in a try-catch block with a custom SettingDecodingError that provides actionable diagnostics including:
   - Exact location in the JSON structure (coding path)
   - Which tool the setting was for
   - Available keys in the malformed setting
   - Helpful guidance about likely causes

Changes:
- Add strictMemorySafety case to SettingName enum
- Add strictMemorySafety(String) case to Kind enum
- Add SettingDecodingError with descriptive error messages
- Handle strictMemorySafety in decoder switch statement
- Handle strictMemorySafety in encoder switch statement

This fixes decoding errors like:
```
keyNotFound(CodingKeys(stringValue: "name", intValue: nil), ...)
```

And replaces them with:
```
Failed to decode target build setting at 'targets.Index 3.settings.Index 0'.
Expected either 'kind' (Xcode 14+ format) or 'name' (legacy format) key, but neither was found.
Tool: swift
Available keys: tool, condition, kind
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 29, 2025
@pepicrft pepicrft requested a review from fortmarek October 29, 2025 19:07
@dosubot dosubot bot added the enhancement New feature or request label Oct 29, 2025
@pepicrft pepicrft merged commit f93b40b into main Oct 29, 2025
7 checks passed
@pepicrft pepicrft deleted the fix/add-strict-memory-safety-setting branch October 29, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants