[Shopify Sync] Fix failure dump with invalid UTF-8 #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Cherry-picks Shopify's UTF-8 encoding fix (commit
ed4ae26). Prevents JSON dump failures when test output contains invalid UTF-8 bytes, ensuring failure reports are always written successfully.Changes
Modified Files
ruby/lib/minitest/queue/failure_formatter.rb- Added UTF-8 encoding with replacementNew Files
ruby/test/minitest/queue/failure_formatter_test.rb- Test for UTF-8 handlingThe Bug
When test output contains invalid UTF-8 bytes (e.g., from binary data, malformed strings), the Ruby JSON library raises an exception because it validates UTF-8 encoding:
This prevents the entire failure report from being written, losing valuable debugging information.
The Fix
Encode output as UTF-8 before JSON serialization, replacing invalid bytes with empty string:
Example
Conflict Resolution
✅ Applied cleanly - No conflicts!
Benefits
Real-World Scenarios
This fixes failures when tests interact with:
Testing
Original Shopify PR
ed4ae26Risk Assessment
Risk Level: Very Low
Additional Notes
The fix uses
replace: ''(empty string) to remove invalid bytes. Alternative would bereplace: '?'to show where bytes were replaced, but empty string is cleaner for most use cases.cc: @Dkeegan