diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index a2f2a08787..0a68ffe92b 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -17,7 +17,11 @@ module Hbc return to_enum unless block_given? Tap.flat_map(&:cask_files).each do |f| - yield CaskLoader::FromTapPathLoader.new(f).load + begin + yield CaskLoader::FromTapPathLoader.new(f).load + rescue CaskUnreadableError => e + opoo e.message + end end end diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 1c41a80691..8c42744f05 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -54,7 +54,15 @@ module Hbc @content = IO.read(path) - instance_eval(content, path) + begin + instance_eval(content, path).tap do |cask| + unless cask.is_a?(Cask) + raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") + end + end + rescue NameError, ArgumentError, ScriptError => e + raise CaskUnreadableError.new(token, e.message) + end end private diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index 243dc458dd..f5e6649e0e 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -36,6 +36,12 @@ module Hbc end end + class CaskUnreadableError < CaskUnavailableError + def to_s + "Cask '#{token}' is unreadable" << (reason.empty? ? "." : ": #{reason}") + end + end + class CaskAlreadyCreatedError < AbstractCaskErrorWithToken def to_s %Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask edit #{token}")} to edit it.)