Skip to content
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

brew failing when typing #19125

Closed
3 tasks done
metalbracket opened this issue Jan 20, 2025 · 4 comments · Fixed by #19151
Closed
3 tasks done

brew failing when typing #19125

metalbracket opened this issue Jan 20, 2025 · 4 comments · Fixed by #19151
Assignees
Labels
bug Reproducible Homebrew/brew bug help wanted We want help addressing this

Comments

@metalbracket
Copy link

metalbracket commented Jan 20, 2025

brew doctor output

Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.4.17
ORIGIN: https://github.com/Homebrew/brew
HEAD: 55f399c10dc7e6cc07497bdfccdecc96329e3b57
Last commit: 23 hours ago
Branch: master
Core tap JSON: 20 Jan 19:49 UTC
Core cask tap JSON: 20 Jan 19:49 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.mAIjh4Rybo/org.xquartz:0
HOMEBREW_EDITOR: codium --wait
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.3.7 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.3.7/bin/ruby
CPU: quad-core 64-bit kabylake
Clang: 15.0.0 build 1500
Git: 2.39.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 13.7-x86_64
CLT: 15.1.0.0.1.1700200546
Xcode: N/A

What were you trying to do (and why)?

I was trying to use brew install to install a package but had caplocks on.

What happened (include all command output)?

brew INSTALL
/usr/local/Homebrew/Library/Homebrew/abstract_command.rb:59: warning: already initialized constant Homebrew::Cmd::InstallCmd::Args
/usr/local/Homebrew/Library/Homebrew/abstract_command.rb:59: warning: previous definition of Args was here
Error: private method `install' called for module Homebrew
/usr/local/Homebrew/Library/Homebrew/brew.rb:97:in `public_send'
/usr/local/Homebrew/Library/Homebrew/brew.rb:97:in `<main>'
Please report this issue:
https://docs.brew.sh/Troubleshooting

What did you expect to happen?

I expected it to install or fail

Step-by-step reproduction instructions (by running brew commands)

brew INSTALL
@metalbracket metalbracket added the bug Reproducible Homebrew/brew bug label Jan 20, 2025
@metalbracket
Copy link
Author

metalbracket commented Jan 20, 2025

Also, it is using ` to open a string and ' to close like in `public_send'?

@MikeMcQuaid MikeMcQuaid added the help wanted We want help addressing this label Jan 21, 2025
@rrotter
Copy link
Contributor

rrotter commented Jan 27, 2025

Seeing a similar problem with brew --cache:

~ % brew --CACHE
Error: undefined method `__cache' for module Homebrew
/opt/homebrew/Library/Homebrew/brew.rb:97:in `public_send'
/opt/homebrew/Library/Homebrew/brew.rb:97:in `<main>'
Please report this issue:
  https://docs.brew.sh/Troubleshooting

#18705 partially addressed this issue here:

begin
Homebrew.public_send Commands.method_name(cmd)
rescue NoMethodError => e
case_error = "undefined method `#{cmd.downcase}' for module Homebrew"
odie "Unknown command: brew #{cmd}" if e.message == case_error

This doesn't handle cases where the string in the NoMethodError is not correctly predicted with cmd.downcase (like --CACHE) or when there actually is a method, but it's private (which is the case for brew INSTALL).

FWIW, the private Homebrew.install method is actually from FileUtils.install:

brew(main):004> Homebrew.method(:install)
=> #<Method: #<Class:Homebrew>(FileUtils)#install(src, dest, mode: ..., owner: ..., group: ..., preserve: ..., noop: ..., verbose: ...) /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.7/lib/ruby/3.3.0/fileutils.rb:1609>

…and it's pulled into the Homebrew module's namespace here:

module Homebrew
extend FileUtils

That has no bearing on a fix, but I spent quite a while looking into that mystery, so I'd thought I'd share.

I'll send a PR shortly that fixes what I've detailed above, but…

The warnings (warning: already initialized constant) are another problem altogether. They are caused by a recursive require, and I'm pretty sure it's actually a ruby bug. The warnings from brew INFO better illuminate what's going on:

~ % brew INFO
/opt/homebrew/Library/Homebrew/cmd/INFO.rb:19: warning: already initialized constant Homebrew::Cmd::Info::VALID_DAYS
/opt/homebrew/Library/Homebrew/cmd/info.rb:19: warning: previous definition of VALID_DAYS was here
/opt/homebrew/Library/Homebrew/cmd/INFO.rb:20: warning: already initialized constant Homebrew::Cmd::Info::VALID_FORMULA_CATEGORIES
/opt/homebrew/Library/Homebrew/cmd/info.rb:20: warning: previous definition of VALID_FORMULA_CATEGORIES was here
/opt/homebrew/Library/Homebrew/cmd/INFO.rb:21: warning: already initialized constant Homebrew::Cmd::Info::VALID_CATEGORIES
/opt/homebrew/Library/Homebrew/cmd/info.rb:21: warning: previous definition of VALID_CATEGORIES was here
/opt/homebrew/Library/Homebrew/abstract_command.rb:59: warning: already initialized constant Homebrew::Cmd::Info::Args
/opt/homebrew/Library/Homebrew/abstract_command.rb:59: warning: previous definition of Args was here

@rrotter
Copy link
Contributor

rrotter commented Jan 27, 2025

I should add, the warnings are produced exactly at this line:

internal_cmd = Commands.valid_internal_cmd?(cmd) || Commands.valid_internal_dev_cmd?(cmd) if cmd

which (counterintuitively?) is where we require the command.

@rrotter
Copy link
Contributor

rrotter commented Jan 27, 2025

@MikeMcQuaid MikeMcQuaid self-assigned this Jan 27, 2025
MikeMcQuaid added a commit that referenced this issue Jan 27, 2025
- hide warnings when requiring files repeatedly on a case-insensitive
  filesystem and add reference to Ruby bugs
- add another case to check for command require failures
- also handle commands with `-` in them

Fixes #19125
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Reproducible Homebrew/brew bug help wanted We want help addressing this
Projects
None yet
3 participants