Homebrew / homebrew-cask

🍻 A CLI workflow for the administration of macOS applications distributed as binaries
https://brew.sh
BSD 2-Clause "Simplified" License
20.83k stars 10.66k forks source link

Unexpected definition error: Invalid url stanza with parameter header #159684

Closed woneiros closed 10 months ago

woneiros commented 10 months ago

Verification

Description of issue

Hi homebrew team, thank you in advance for you time!

We are building our own formulas and casks, and when trying to install a small cask I'm getting a weird cask definition error that says:

Error: Cask 'cask-test' definition is invalid: 'url' stanza failed with: 
Parameter 'header': Expected type T.nilable(String), got type Array with value ["Accept: application/octet-stream"]

Note: This error occurs after I already added the correct tap: brew tap tkupek/homebrew-cask-test https://github.com/tkupek/homebrew-cask-test.git

We've tried to create a minimal reproducible example, and this cask formula is still giving me the error: You can also see the repo here: https://github.com/tkupek/homebrew-cask-test

cask "cask-test" do
  desc "Foobar"
  homepage "https://github.com/tkupek/homebrew-cask-test"
  version "v0.0.1"

  on_arm do
    url "https://api.github.com/repos/tkupek/homebrew-cask-test/releases/assets/134513898",
      header: [
        "Accept: application/octet-stream",
      ]
    sha256 "11d08b197f303f638e3663f0f14e0a5fb3587e64b07d4691c63d5d18e90460a0"

    app "APK Icon Editor.app"
  end

  on_intel do
    url "https://api.github.com/repos/tkupek/homebrew-cask-test/releases/assets/134513898",
      header: [
        "Accept: application/octet-stream",
      ]
    sha256 "11d08b197f303f638e3663f0f14e0a5fb3587e64b07d4691c63d5d18e90460a0"

    app "APK Icon Editor.app"
  end
end

The above definition works if we update the header to simply be a string, but in our actual usecase we need to set two headers. This supposedly follows the formula definition docs https://docs.brew.sh/Cask-Cookbook#stanza-url , and it works for a colleague that has the same exact brew config Ruby version number. So I'm quite stumped.

Command that failed

brew install --cask cask-test

Output of command with --verbose --debug

Error: Cask 'cask-test' definition is invalid: 'url' stanza failed with: Parameter 'header': Expected type T.nilable(String), got type Array with value ["Accept: application/octet-stream"]
Caller: /usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:113
Definition: /usr/local/Homebrew/Library/Homebrew/cask/url.rb:172
/usr/local/Homebrew/Library/Homebrew/cask/dsl.rb:139:in `rescue in set_unique_stanza'
/usr/local/Homebrew/Library/Homebrew/cask/dsl.rb:121:in `set_unique_stanza'
/usr/local/Homebrew/Library/Homebrew/cask/dsl.rb:202:in `url'
/usr/local/Homebrew/Library/Taps/tkupek/homebrew-cask-test/Casks/cask-test.rb:18:in `block (2 levels) in load'
/usr/local/Homebrew/Library/Homebrew/extend/on_system.rb:60:in `block (2 levels) in setup_arch_methods'
/usr/local/Homebrew/Library/Taps/tkupek/homebrew-cask-test/Casks/cask-test.rb:17:in `block in load'
/usr/local/Homebrew/Library/Homebrew/cask/cask.rb:102:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/cask.rb:102:in `refresh'
/usr/local/Homebrew/Library/Homebrew/cask/cask.rb:95:in `config='
/usr/local/Homebrew/Library/Homebrew/cask/cask.rb:74:in `initialize'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `validate_call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:46:in `new'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:46:in `cask'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `validate_call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:130:in `cask'
/usr/local/Homebrew/Library/Taps/tkupek/homebrew-cask-test/Casks/cask-test.rb:2:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:115:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:115:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/cask_loader.rb:413:in `load'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:159:in `block in load_formula_or_cask'
/usr/local/Homebrew/Library/Homebrew/api.rb:197:in `with_no_api_env_if_needed'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `validate_call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:118:in `load_formula_or_cask'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:83:in `block in to_formulae_and_casks'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `each'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `flat_map'
/usr/local/Homebrew/Library/Homebrew/cli/named_args.rb:81:in `to_formulae_and_casks'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/call_validation.rb:157:in `validate_call'
/usr/local/Homebrew/Library/Homebrew/vendor/bundle/ruby/2.6.0/gems/sorbet-runtime-0.5.10461/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
/usr/local/Homebrew/Library/Homebrew/cmd/install.rb:195:in `install'
/usr/local/Homebrew/Library/Homebrew/brew.rb:86:in `<main>'

Output of brew doctor and brew config

❯ brew config
HOMEBREW_VERSION: 4.1.19-23-g12d491b
ORIGIN: https://github.com/Homebrew/brew
HEAD: 12d491b87292135648a8bb09ee2a0645c4f89fb0
Last commit: 4 minutes ago
Core tap JSON: 08 Nov 17:34 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.LwIBXlp3Kw/org.xquartz:0
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit icelake
Clang: 15.0.0 build 1500
Git: 2.39.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 14.0-x86_64
CLT: 15.0.0.0.1.1694021235
Xcode: 15.0.1
❯ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  openssl@1.1

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
  /usr/local/lib/libtcl8.6.dylib
  /usr/local/lib/libtk8.6.dylib

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected header files:
  /usr/local/include/fakemysql.h
  /usr/local/include/fakepq.h
  /usr/local/include/fakesql.h
  /usr/local/include/itcl.h
  /usr/local/include/itcl2TclOO.h
  /usr/local/include/itclDecls.h
  /usr/local/include/itclInt.h
  /usr/local/include/itclIntDecls.h
  /usr/local/include/itclMigrate2TclCore.h
  /usr/local/include/itclTclIntStubsFcn.h
  /usr/local/include/mysqlStubs.h
  /usr/local/include/odbcStubs.h
  /usr/local/include/pqStubs.h
  /usr/local/include/tcl.h
  /usr/local/include/tclDecls.h
  /usr/local/include/tclOO.h
  /usr/local/include/tclOODecls.h
  /usr/local/include/tclPlatDecls.h
  /usr/local/include/tclThread.h
  /usr/local/include/tclTomMath.h
  /usr/local/include/tclTomMathDecls.h
  /usr/local/include/tdbc.h
  /usr/local/include/tdbcDecls.h
  /usr/local/include/tdbcInt.h
  /usr/local/include/tk.h
  /usr/local/include/tkDecls.h
  /usr/local/include/tkPlatDecls.h

Warning: Unbrewed '.pc' files were found in /usr/local/lib/pkgconfig.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected '.pc' files:
  /usr/local/lib/pkgconfig/tcl.pc
  /usr/local/lib/pkgconfig/tk.pc

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
  /usr/local/lib/libtclstub8.6.a
  /usr/local/lib/libtkstub8.6.a

Output of brew tap

❯ brew tap
azure/kubelogin
coursier/formulas
good-research/capture-companion
good-research/gr-recce
good-research/gr-sawdust
hashicorp/tap
homebrew/cask
homebrew/cask-fonts
mongodb/brew
romkatv/powerlevel10k
supabase/tap
tkupek/cask-test
withgraphite/tap
bevanjkay commented 10 months ago

Have you tried passing the array through to headers instead?

woneiros commented 10 months ago

Thank you for your reponse @bevanjkay

Yes, in that case I get the following error:

❯ brew install --cask cask-anothertest
Error: Cask 'cask-anothertest' definition is invalid: 'url' stanza failed with: unknown keyword: headers

I just created a separate reproducible cask for this. Available here: https://github.com/woneiros/homebrew-cask-anothertest With formula:

cask "cask-anothertest" do
  desc "Foobar2"
  homepage "https://github.com/tkupek/homebrew-cask-test"
  version "v0.0.1"

  on_arm do
    url "https://api.github.com/repos/tkupek/homebrew-cask-test/releases/assets/134513898",
      headers: [
        "Accept: application/octet-stream",
      ]
    sha256 "11d08b197f303f638e3663f0f14e0a5fb3587e64b07d4691c63d5d18e90460a0"

    app "APK Icon Editor.app"
  end

  on_intel do
    url "https://api.github.com/repos/tkupek/homebrew-cask-test/releases/assets/134513898",
      headers: [
        "Accept: application/octet-stream",
      ]
    sha256 "11d08b197f303f638e3663f0f14e0a5fb3587e64b07d4691c63d5d18e90460a0"

    app "APK Icon Editor.app"
  end
end
woneiros commented 10 months ago

awesome, it's working now. Thank you @bevanjkay and @Bo98!