Merge pull request #4673 from rolandwalker/cask_load_exceptions

Improve error checking and messages on Cask load
This commit is contained in:
Roland Walker
2014-06-06 20:42:35 -04:00
2 changed files with 22 additions and 5 deletions
+17 -2
View File
@@ -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
+5 -3
View File
@@ -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