Homebrew-cask: undefined method `undent'

Created on 16 Jul 2018  路  17Comments  路  Source: Homebrew/homebrew-cask

General troubleshooting steps

  • [X] I have retried my command with --force and the issue is still present.
  • [X] I have checked the instructions for reporting bugs.
  • [X] None of the templates was appropriate for my issue, or I鈥檓 not sure.
  • [X] I ran brew update-reset && brew update and retried my command.
  • [X] I ran brew doctor, fixed as many issues as possible and retried my command.
  • [X] I understand that if I ignore these instructions, my issue may be closed without review.

Description of issue

I am trying to do a brew cask upgrade --greedy, but I get an error related to an undefined method on it.

Command that failed

brew cask upgrade --greedy

Output of command with --force --verbose --debug

==> Casks with `auto_updates` or `version :latest` will not be upgraded
==> Upgrading 1 outdated package, with result:
powershell 6.0.2
==> Started upgrade process for Cask powershell
Error: undefined method `undent' for #<String:0x00007f9f3525c098>
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/usr/local/Caskroom/powershell/.metadata/6.0.0-beta.8/20171012033107.351/Casks/powershell.rb:35:in `block in load'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask.rb:36:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask.rb:36:in `initialize'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:31:in `new'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:31:in `cask'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:67:in `cask'
/usr/local/Homebrew/Library/Homebrew/compat/hbc/cask_loader.rb:15:in `cask'
/usr/local/Caskroom/powershell/.metadata/6.0.0-beta.8/20171012033107.351/Casks/powershell.rb:1:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:57:in `instance_eval'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:57:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cask_loader.rb:170:in `load'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:37:in `block in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:33:in `each'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/upgrade.rb:33:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb:33:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:93:in `run_command'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:157:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:122:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:7:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'
Error: Kernel.exit
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:168:in `exit'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:168:in `rescue in run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:145:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/lib/hbc/cli.rb:122:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:7:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:100:in `<main>'

Output of brew cask doctor

==> Homebrew-Cask Version
Homebrew-Cask 1.7.0-9-gc47d515
Homebrew/homebrew-cask (git revision ba212; last commit 2018-07-16)
==> macOS
10.13.6
==> SIP
Enabled
==> Java
1.8.0_151
==> Homebrew-Cask Install Location
<NONE>
==> Homebrew-Cask Staging Location
/usr/local/Caskroom
==> Homebrew-Cask Cached Downloads
~/Library/Caches/Homebrew/Cask (6 files, 83.4MB)
==> Homebrew-Cask Taps:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask (3996 casks)
==> Contents of $LOAD_PATH
/usr/local/Homebrew/Library/Homebrew
/usr/local/Homebrew/Library/Homebrew/cask/lib
/Library/Ruby/Gems/2.3.0/gems/did_you_mean-1.0.0/lib
/Library/Ruby/Site/2.3.0
/Library/Ruby/Site/2.3.0/x86_64-darwin17
/Library/Ruby/Site/2.3.0/universal-darwin17
/Library/Ruby/Site
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0/x86_64-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby/2.3.0/universal-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/vendor_ruby
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/x86_64-darwin17
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin17
==> Environment Variables
LC_ALL="en_US.UTF-8"
PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Homebrew/Library/Homebrew/shims/scm"
SHELL="/bin/bash

Output of brew tap

homebrew/cask
homebrew/core
awaiting maintainer feedback bug core

Most helpful comment

My manual workaround for the error:

Error: undefined method `undent' for #<String:0x00000001029af2d8>
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/usr/local/Caskroom/jce-unlimited-strength-policy/.metadata/1.8/20170518201102.343/Casks/jce-unlimited-strength-policy.rb:65:in `block in load'

was to edit /usr/local/Caskroom/jce-unlimited-strength-policy/.metadata/1.8/20170518201102.343/Casks/jce-unlimited-strength-policy.rb and remove the .undent.

This fixed: brew cu.

I then removed this old cask with: brew cask uninstall jce-unlimited-strength-policy

All 17 comments

If you ignore this guide, your issue may be closed without review.

Also note from that document:

If the maintainer was wrong in closing your issue, please do reply stating why! Closing an issue does not mean the conversation is over. If the guides themselves were unclear, help us improve them! Open first an issue or pull request stating what you found confusing and only then your other issue.

Hi @vitorgalvao, I have edited my issue. I didn't see the template until you put the link above. It would be cool if you could link the template to "My problem isn't listed" section. Thank you and sorry for the mess.

This was caused by a recent commit. Others are having the same issue.

See https://github.com/Homebrew/brew/issues/4494. Should be fixed soon. Thank you for the report.

According to https://github.com/Homebrew/brew/issues/4494#issuecomment-406598112 - this homebrew-cask-specific issue ought to be re-opened.

I agree. Cask files in .metadata using methods that no longer exist should fall back to the cask file in the tap (like in Homebrew itself).

Cask files in .metadata using methods that no longer exist should fall back to the cask file in the tap (like in Homebrew itself).

This could potentially cause problems when uninstalling/upgrading.

I see two solutions. Either readd String#undent or add a migration which replaces all occurrences of <<-EOS.undent with <<~EOS in Caskroom.

Either readd String#undent

This method was deprecated then disabled then removed. I don't think this is an option (and it bodes poorly for future removals).

add a migration which replaces all occurrences of <<-EOS.undent with <<~EOS in Caskroom.

Similarly, this bodes poorly for future removals and seems error-prone. What was the <<-EOS.undent code doing with the deprecations and disables previously? Just blindly ignoring them? That seems like a pretty big bug if so. If they weren't being ignored but instead you were falling back to loading from the tap: that seems like the best idea.

Cask files in .metadata using methods that no longer exist should fall back to the cask file in the tap (like in Homebrew itself).

This is the approach Homebrew has taken with formula files (use .brew/formula.rb unless it cannot be read or has invalid syntax) and it works well there unless the Cask has since been removed from the tap in which case we act on the formula as if it was essentially default/blank. I'd strongly suggest Cask takes the same approach.

In general I think writing a Ruby file that calls Homebrew APIs into the Caskroom and expecting that to work regardless of the version of Homebrew it was written with and Homebrew is now is doomed to fail.

license will also likely have similar issues when it is deleted (it's currently disabled) even although it hasn't existed in the taps for two years.

I agree that it isn't great but a migration to handle these cases seems like the best option as falling back to the tap will cause issues when the uninstall procedure differs from what is in the cask .metadata.

Um, yes:

https://github.com/Homebrew/brew/blob/7ad999f5f8be61854d5dcfce84fbbfe16a4656a3/Library/Homebrew/utils.rb#L91-L96

@reitermarkus I'm now wondering if a better option there would be to raise an exception that the formula isn't readable (which is handled elsewhere).

I agree that it isn't great but a migration to handle these cases seems like the best option as falling back to the tap will cause issues when the uninstall procedure differs from what is in the cask .metadata.

I think writing Ruby code to rewrite existing Ruby code every time we want to delete deprecated code is going to be error-prone. For Cask specifically I'd advise ASAP writing the minimal Cask data e.g. just the uninstall hook (perhaps even as a Bash script rather than Ruby) to avoid this time-bomb in future.

My manual workaround for the error:

Error: undefined method `undent' for #<String:0x00000001029af2d8>
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/usr/local/Caskroom/jce-unlimited-strength-policy/.metadata/1.8/20170518201102.343/Casks/jce-unlimited-strength-policy.rb:65:in `block in load'

was to edit /usr/local/Caskroom/jce-unlimited-strength-policy/.metadata/1.8/20170518201102.343/Casks/jce-unlimited-strength-policy.rb and remove the .undent.

This fixed: brew cu.

I then removed this old cask with: brew cask uninstall jce-unlimited-strength-policy

hi, @vitorgalvao, I come across the same problem. brew install mysql, and get the error:
undefined method undent
I see that you said Homebrew/brew#4494 would fix the problem. However, I still can not fix it .
finally, I remove the undent method in some files , and brew install mysql successfully. The files I edit is:
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/sphinx-doc.rb
14 keg_only <<-EOS.undent
15 This formula is mainly used internally by other formulae.
16 Users are advised to use pip to install sphinx-doc.
17 EOS
116 <<-EOS.undent
117 #ifdef __#{arch}__
118 #{(buildpath/"build-#{arch}/opensslconf.h").read}
119 #endif
120 EOS

def caveats; <<-EOS.undent
154 A CA file has been bootstrapped using certificates from the SystemRoots
155 keychain. To add additional certificates (e.g. the certificates added in
156 the System keychain), place .pem files in
157 #{openssldir}/certs
158
159 and run
160 #{opt_bin}/c_rehash
161 EOS

I still doubt if this is the right method to fix the problem. And if there is better solution?
brew list
mysql openssl tree
bogon:~ bruce$ brew config
HOMEBREW_VERSION: 1.7.1
ORIGIN: https://github.com/Homebrew/brew
HEAD: d6a245c05110c240e680da594c2cc6038998b82e
Last commit: 2 weeks ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: c80ece7daa5e88d9f9903a6fa2b88a034caf50bd
Core tap last commit: 1 year, 3 months ago
HOMEBREW_PREFIX: /usr/local
CPU: quad-core 64-bit skylake
Homebrew Ruby: 2.3.7 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.7/bin/ruby
Clang: 9.0 build 900
Git: 2.14.3 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.54.0 => /usr/bin/curl
Java: N/A
macOS: 10.12.6-x86_64
CLT: 9.2.0.0.1.1510905681
Xcode: N/A
XQuartz: N/A

Hi, same issue when reinstalling java.
Submitted here: https://github.com/Homebrew/homebrew-cask/issues/50727

I had the same problem, when calling brew cask outdated. I got:

Error: undefined method 'undent' for #<String:0x00000001033df870>

I then tried to solve it as follows:

cd $(brew --repo); git fetch; git reset --hard origin/master; brew update
...
HEAD is now at 3e289aa6c4 Merge pull request #4702 from MikeMcQuaid/kernel-exit-debug Already up-to-date.

Now the massage changed to:

brew cask outdated
Error: Cask 'java7' is unreadable: undefined method 'undent' for #<String:0x0000000102069f20>

This already shows where the problem really lies. I just checket caskroom folder for java7:
ll /usr/local/Caskroom/java7/1.7.0_80

and found an empty folder... ?!
Double checked with:

brew reinstall java7
Error: No available formula with the name "java7"

Why is there no more java7? No matter, just removed java7
rm -rf /usr/local/Caskroom/java7
jenv remove oracle64-1.7.0.80
JDK oracle64-1.7.0.80 removed
...

And here we go...:

brew cask outdated
audio-hijack (3.5.1) != 3.5.3
cmake (3.11.4) != 3.12.1
...

Locking the issue because we鈥檙e getting pile ups of the same bug report. We understand the problem, we鈥檙e discussing how to go about handling these cases where deprecations break uninstalls.

In the meantime, for whoever stumbles here, the workaround is this one, adapted to the problematic casks. Here鈥檚 a one liner that should fix them all for you. I recommend you backup "$(brew --prefix)/Caskroom/ in case something goes wrong.

find "$(brew --prefix)/Caskroom/"*'/.metadata' -type f -name '*.rb' | xargs grep 'EOS.undent' --files-with-matches | xargs sed -i '' 's/EOS.undent/EOS/'
Was this page helpful?
0 / 5 - 0 ratings