Skip to content

formulary: prevent formulae from printing to stdout while being loaded #20226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 10, 2025

Conversation

carlocab
Copy link
Member

@carlocab carlocab commented Jul 9, 2025

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Formulae can execute arbitrary Ruby code when being loaded. In
particular, they can print to stdout with methods like puts. This can
break the parsing of output of commands like brew info --json=v2.

Let's fix that by capturing the output to stdout, and then printing
those messages to stderr instead (using opoo to try to discourage
formula authors from doing this).

Formulae can execute arbitrary Ruby code when being loaded. In
particular, they can print to stdout with methods like `puts`. This can
break the parsing of output of commands like `brew info --json=v2`.

Let's fix that by capturing the output to stdout, and then printing
those messages to stderr instead (using `opoo` to try to discourage
formula authors from doing this).
@carlocab carlocab requested a review from Bo98 July 9, 2025 20:07
@carlocab carlocab self-assigned this Jul 9, 2025
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Looks good! Tap name would be nice but not a blocker. Suggested style tweak.

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
@carlocab carlocab force-pushed the formula-loading-stdout branch from 739a582 to 69ce5ed Compare July 10, 2025 12:28
@carlocab carlocab enabled auto-merge July 10, 2025 12:28
@carlocab carlocab added this pull request to the merge queue Jul 10, 2025
Merged via the queue into main with commit 0b99d57 Jul 10, 2025
33 checks passed
@carlocab carlocab deleted the formula-loading-stdout branch July 10, 2025 12:59
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.

3 participants