Closed apainintheneck closed 6 months ago
This is just one example of the problems that loading from installed cask files can cause.
It seems like we try to load casks using Cask::Cask#sourcefile_path as the ref and that causes problems sometimes because the source file path is nilable depending on which cask loader is used. We use this pattern in a few places to reload the same cask for different os/arch combinations. In this case, it was nil because it was loading the installed cask file instead of the one from the core cask repo.
I almost feel like there are some commands where we don’t want certain cask loaders to be used. Beyond that I wonder if we’d be able to catch this type of error beforehand with more typing in the Cask::Cask and Cask::CaskLoader classes.
-- Rescued from internal team slack
The solution for brew bump
is to require all loaded casks and formulae to be in installed taps. This pattern shows up in a few other places though and in those cases things should maybe be handled differently. It might not even be a problem if we know the cask will always have this field.
brew --cache
brew fetch
brew audit
brew bump-cask-pr
~Edit: This already gets checked for casks without associated taps which solves this problem.
brew bump
brew livecheck
It looks like what happens with a core formula when the core tap is not installed is that we load it from the keg and then use the path the installed formula file when reloading the formula for different architectures.
$ brew audit gawk --verbose --debug
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/3.1.0/bin/bundle clean
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromKegLoader): loading gawk
/usr/local/Homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::NullLoader): loading gawk
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromKegLoader): loading gawk
/usr/local/Homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::NullLoader): loading gawk
/usr/bin/env XDG_CACHE_HOME=/Users/kevinrobell/Library/Caches/Homebrew/style /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby -W1 --disable=gems,rubyopt -- /usr/local/Homebrew/Library/Homebrew/utils/rubocop.rb --format json --force-exclusion --parallel --extra-details --except FormulaAuditStrict --config /usr/local/Homebrew/Library/.rubocop.yml /usr/local/opt/gawk/.brew/gawk.rb
==> Auditing Formula gawk on os catalina and arch intel
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromPathLoader): loading /usr/local/opt/gawk/.brew/gawk.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading gettext
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading mpfr
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading readline
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading curl
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading pkg-config
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading brotli
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading cmake
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading libidn2
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading libunistring
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading libnghttp2
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading libssh2
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading openssl@3
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading ca-certificates
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading openldap
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading rtmpdump
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading zstd
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading lz4
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading xz
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromAPILoader): loading gmp
We could easily make casks work the same way but I'm not sure it really captures the desired behavior of most of the dev commands. It'd still be an improvement though since it wouldn't fail loudly. In general, the livecheck
, bump*
and audit
commands assume the core taps are tapped locally.
Maybe we could add some way of turning off installed formula/cask file loading in the parser and then update Formulary.loader_for
and Cask::CaskLoader.for
to respect that.
It'd still be an improvement though since it wouldn't fail loudly. In general, the
livecheck
,bump*
andaudit
commands assume the core taps are tapped locally.
Simplest/best case I think would be to make said commands exit (very) early if the relevant formula's tap is not tapped.
Maybe we could add some way of turning off installed formula/cask file loading in the parser and then update
Formulary.loader_for
andCask::CaskLoader.for
to respect that.
This seems like it might be a lot more complex than the prior option unless we somehow have some commands that need to load only from tap in some places but are fine with API in others.
That makes sense to me. Looking at things a bit more, I see now that the bump-*-pr
commands already do that as of a few years ago. That approach should work well.
The fetch
and --cache
each have a lower likelihood of errors because they default to the name if the cask is loaded from the API which happens when loading from the installed cask JSON. Technically you could still see the same problem with casks installed from third-party taps though.
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 was trying to reproduce this cask loading issue: https://github.com/orgs/Homebrew/discussions/4910#discussioncomment-8750211
CC: @johnmcdowell
What happened (include all command output)?
What did you expect to happen?
It shouldn't cause a type error.
Step-by-step reproduction instructions (by running
brew
commands)