From 787b471618b8f10de261e572cf5b91d4b863f026 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 3 Jun 2014 11:39:58 -0400 Subject: [PATCH 1/2] isolate ErrorDuringExecution rescue it only should be rescued for the `curl` invocation --- lib/cask/source/uri.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cask/source/uri.rb b/lib/cask/source/uri.rb index 34ffc0a0f7..3f6dffe9b6 100644 --- a/lib/cask/source/uri.rb +++ b/lib/cask/source/uri.rb @@ -14,10 +14,12 @@ class Cask::Source::URI path = HOMEBREW_CACHE_CASKS.join(File.basename(uri)) ohai "Downloading #{uri}" odebug "Download target -> #{path.to_s}" - curl(uri, '-o', path.to_s) + begin + curl(uri, '-o', path.to_s) + rescue ErrorDuringExecution + raise CaskUnavailableError.new uri + end Cask::Source::PathSlashOptional.new(path).load - rescue ErrorDuringExecution - raise CaskUnavailableError, uri end def to_s From c082b5521a4d7cf673b88b55028a70b2d0ad3b4b Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 3 Jun 2014 11:42:32 -0400 Subject: [PATCH 2/2] Improve error checking and messages on Cask load Other Cask sources ultimately invoke the `load` method in the abstract class Cask::Source::PathBase, so these changes apply to all other sources. --- lib/cask/source/path_base.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/cask/source/path_base.rb b/lib/cask/source/path_base.rb index 8c03e9cf15..ff62fb8346 100644 --- a/lib/cask/source/path_base.rb +++ b/lib/cask/source/path_base.rb @@ -15,8 +15,23 @@ class Cask::Source::PathBase end def load - require path - Cask.const_get(cask_class_name).new + raise CaskError.new "File '#{path}' does not exist" unless path.exist? + raise CaskError.new "File '#{path}' is not readable" unless path.readable? + raise CaskError.new "File '#{path}' is not a plain file" unless path.file? + begin + require path + rescue CaskError, StandardError, ScriptError => e + # bug: e.message.concat doesn't work with CaskError exceptions + e.message.concat(" while loading '#{path}'") + raise e + end + begin + Cask.const_get(cask_class_name).new + rescue CaskError, StandardError, ScriptError => e + # bug: e.message.concat doesn't work with CaskError exceptions + e.message.concat(" while instantiating '#{cask_class_name}' from '#{path}'") + raise e + end end def cask_class_name