Skip to content

Preserve build errors with Pathname arguments - #24292

Merged
MikeMcQuaid merged 1 commit into
mainfrom
pathname-build-error-json
Oct 18, 2026
Merged

MikeMcQuaid merged 1 commit into
mainfrom
pathname-build-error-json

Conversation

@MikeMcQuaid

@MikeMcQuaid MikeMcQuaid commented Oct 17, 2026 •

Copy link
Copy Markdown
Member
  • Stringify BuildError commands and arguments so JSON reporting preserves the original failure when formulae pass Pathnames.

Fixes #24291


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Codex with GPT 6 Astra at Extra High effort, with local review and testing.


Summary by CodeRabbit

  • Bug Fixes
    • Build errors reported across a fork now retain command and argument details, including commands represented as paths and arguments of different types. Error messages, environment details, and backtraces are also preserved, making the reported failure more complete.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df49a9f2-03f4-427a-9909-a0cfd4ad9c11
📥 Commits

Reviewing files that changed from the base of the PR and between 997c536 and b859f85.

📒 Files selected for processing: 1
  • Library/Homebrew/test/utils/fork_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

Build error reporting now converts BuildError command and argument values to strings before JSON serialisation. A test checks that a reported error containing Pathname values can be reconstructed from the JSON-parsed report.

Changes: Build error serialisation

Layer / File(s) Summary
Stringify and reconstruct BuildError values
Library/Homebrew/utils/fork.rb, Library/Homebrew/test/utils/fork_spec.rb
Utils.child_error_hash converts BuildError#cmd and each BuildError#args value to a string. The test checks reconstruction of the reported error after JSON parsing.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to b859f

The forked-child error report preserves Pathname command and argument values as strings through reconstruction. No actionable merge-blocking risk was identified.

### Architecture Summary

Architecture risk: 🔵 Low · up to b859f

The change affects 1 system.

Changed systems: Library

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — Library (service) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in Library/Homebrew/utils/fork.rb: BuildError command and argument values are converted to strings before being added to the child error hash; previously, their original values were stored.
  • observed — Modified behavior in Library/Homebrew/test/utils/fork_spec.rb: Adds coverage for reporting and rewriting a BuildError with a Pathname command and mixed-type arguments, asserting the reconstructed error’s fields and string-normalised command and arguments.
Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: preserving build errors when command arguments are Pathname values.
Linked Issues check Passed The change meets the coding requirements in issue #24291. Utils.child_error_hash converts BuildError#cmd and each BuildError#args value to strings before JSON encoding. This prevents Pathname …
Out of Scope Changes check Passed The pull request changes only Library/Homebrew/utils/fork.rb and its focused test. The implementation fixes BuildError serialisation, and the test covers the affected reporter path. No unrelated c…
Full details: Linked Issues check

Explanation

The change meets the coding requirements in issue #24291. Utils.child_error_hash converts BuildError#cmd and each BuildError#args value to strings before JSON encoding. This prevents Pathname values from reaching the JSON generator. The new fork_spec.rb example verifies command, arguments, environment, message, and backtrace preservation through reporting and error rewriting.

Full details: Out of Scope Changes check

Explanation

The pull request changes only Library/Homebrew/utils/fork.rb and its focused test. The implementation fixes BuildError serialisation, and the test covers the affected reporter path. No unrelated changes are present in the reviewed diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments: 1
Library/Homebrew/test/utils/fork_spec.rb: 1

31-42: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the reconstructed BuildError fields directly.

Exception#== does not compare BuildError#cmd, BuildError#args, or BuildError#env. The current fixture converts Pathname, Integer, and Symbol values to strings during serialisation, but the generated message remains equal. The test can therefore pass while the reconstructed fields are altered.

✅ Suggested fix to assert the reconstructed values
-      error = BuildError.new(nil, Pathname("/bin/false"), ["arg1", 2, Pathname("arg 3"), :arg4], {})
+      error = BuildError.new(nil, Pathname("/bin/false"), ["arg1", 2, Pathname("arg 3"), :arg4], { "PATH" => "/bin" })
       error.set_backtrace ["/some/file.rb:1:in 'block'"]

       IO.pipe do |reader, writer|
         described_class.report_forked_child_error(writer, error)

-        expect(described_class.rewrite_child_error(JSON.parse(reader.read))).to eq(error)
+        rewritten = described_class.rewrite_child_error(JSON.parse(reader.read))
+        expect(rewritten).to eq(error)
+        expect(rewritten).to have_attributes(
+          cmd:  "/bin/false",
+          args: ["arg1", "2", "arg 3", "arg4"],
+          env:  { "PATH" => "/bin" },
+        )
       end

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ed1b977-9478-4b2d-acc8-2ef19f86a0d8
📥 Commits

Reviewing files that changed from the base of the PR and between 013821d and 997c536.

📒 Files selected for processing: 2
  • Library/Homebrew/test/utils/fork_spec.rb
  • Library/Homebrew/utils/fork.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

- Stringify `BuildError` commands and arguments so JSON reporting
  preserves the original failure when formulae pass `Pathname`s.
- Assert reconstructed fields so error equality cannot hide data loss.

Fixes #24291
@MikeMcQuaid
MikeMcQuaid force-pushed the pathname-build-error-json branch from 997c536 to b859f85 Compare October 17, 2026 19:16
@MikeMcQuaid
MikeMcQuaid enabled auto-merge October 17, 2026 19:16
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 18, 2026
Merged via the queue into main with commit 3073d6a Oct 18, 2026
53 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the pathname-build-error-json branch October 18, 2026 02:53
@dduugg dduugg mentioned this pull request Oct 18, 2026
7 of 8 tasks
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-Homebrew__brew that referenced this pull request Oct 18, 2026
- Homebrew#24292 stringified `BuildError` fields but `ErrorDuringExecution`
  commands can also hold `Pathname`s, which still raised
  `JSON::GeneratorError` and hid the real child error.
- Convert `Pathname`s in the `JSON::Coder` block so every error type
  and field is covered.
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.

Pathname not allowed in JSON: the reporter crashes and hides the real error when Formula#system fails with a Pathname argument

3 participants