-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Error: undefined method `each' for nil #19142
Comments
The error message notwithstanding, $ brew list python
brew list python
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/idle3
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/idle3.13
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/pip3
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/pip3.13
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/pydoc3
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/pydoc3.13
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/python3
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/python3-config
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/python3.13
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/python3.13-config
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/wheel3
/opt/homebrew/Cellar/python@3.13/3.13.1/bin/wheel3.13
/opt/homebrew/Cellar/python@3.13/3.13.1/Frameworks/Python.framework/ (3272 files)
/opt/homebrew/Cellar/python@3.13/3.13.1/IDLE 3.app/Contents/ (8 files)
/opt/homebrew/Cellar/python@3.13/3.13.1/lib/pkgconfig/ (4 files)
/opt/homebrew/Cellar/python@3.13/3.13.1/libexec/bin/ (6 files)
/opt/homebrew/Cellar/python@3.13/3.13.1/libexec/wheel-0.45.1-py3-none-any.whl
/opt/homebrew/Cellar/python@3.13/3.13.1/Python Launcher 3.app/Contents/ (16 files)
/opt/homebrew/Cellar/python@3.13/3.13.1/sbom.spdx.json
/opt/homebrew/Cellar/python@3.13/3.13.1/share/man/ (2 files) You can add a $ brew list python | xargs -t brew uninstall --force
brew uninstall --force --verbose --debug /opt/homebrew/Cellar/python@3.13/3.13.1/INSTALL_RECEIPT.json /opt/homebrew/Cellar/python@3.13/3.13.1/LICENSE /opt/homebrew/Cellar/python@3.13/3.13.1/bin/pydoc3.13 /opt/homebrew/Cellar/python@3.13/3.13.1/bin/wheel3 /opt/homebrew/Cellar/python@3.13/3.13.1/bin/python3 [...] |
From the stacktrace seems like it's trying to load a cask from the API and for some reason the JSON is missing the artifacts array. brew/Library/Homebrew/cask/cask_loader.rb Line 403 in 3ebcbbb
It's not obvious why the output of |
As already mentioned, the exact command usage is wrong. In this case, an error is expected; however, it looks like the existing exception should be caught and a more descriptive one should be raised instead (CaskUnreadableError or something else). Specifically, API loader doesn't cleanly deal with arbitrary JSON files, e.g. ❯ brew ruby -e 'Cask::CaskLoader.load("/opt/homebrew/Cellar/python@3.13/3.13.1/INSTALL_RECEIPT.json")'
/opt/homebrew/Library/Homebrew/cask/cask_loader.rb:403:in `block in load': undefined method `each' for nil (NoMethodError)
from /opt/homebrew/Library/Homebrew/cask/cask.rb:116:in `instance_eval'
...
❯ brew info /opt/homebrew/Cellar/python@3.13/3.13.1/INSTALL_RECEIPT.json
Error: undefined method `each' for nil
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace JSON files are attempted to be loaded as a Cask at: brew/Library/Homebrew/cask/cask_loader.rb Lines 138 to 139 in 3ebcbbb
One option could be moving that line into the exception handling block afterward, which would then result in: ❯ brew info /opt/homebrew/Cellar/python@3.13/3.13.1/INSTALL_RECEIPT.json
Error: Cask 'INSTALL_RECEIPT' is unreadable: undefined method `each' for nil Though perhaps this input should have been rejected earlier on. Not familiar if API is supposed to work off arbitrary JSON files. |
You're right that the original command was wrong but I'd have expected the failure to be better in this case. Also, nice working figuring out that the problem was the JSON file. The current logic requires us to be able to load casks from JSON files since that is the only representation of a cask that was installed using the API. For formulae we just store the original Ruby file since that's included automatically with the bottle if I remember correctly. That being said I don't think we should be trying to load random JSON files as casks from file paths given by the user even though it's still occasionally needed internally. If my memory serves me, we try to use the original cask definition (from either a Ruby or JSON file) when uninstalling casks. I'm not sure where else it's used off the top of my head. Did we ever get rid of the ability to install formulae directly from file paths? I remember there was some discussion about that sort of thing before but I don't remember what happened in the end. It'd be nice to prevent JSON file loading for the same reasons here. |
We attempted a deprecation but it got backed out because it was very involved and no-one (read: me) was motivated enough to get it over the line again. |
Yeah, maybe it's not worth the effort then. |
I think it probably still is but just worth noting it's a non-trivial lift. Might be a good candidate to try at the AGM... |
brew doctor
outputVerification
brew doctor
output" above saysYour system is ready to brew.
and am still able to reproduce my issue.brew update
twice and am still able to reproduce my issue.brew install wget
. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.brew config
outputWhat were you trying to do (and why)?
I tried to run this command
brew list python | xargs brew uninstall --force
What happened (include all command output)?
What did you expect to happen?
I was expecting to remove all python installations
Step-by-step reproduction instructions (by running
brew
commands)The text was updated successfully, but these errors were encountered: