diff options
| author | Drew Rodman | 2014-02-18 15:08:03 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-02-18 15:08:03 -0500 | 
| commit | d63ef14794c60464108be85cb5eeedb829261cab (patch) | |
| tree | 90035f324d724ab9e37a82527a823e9b61292abd /Library | |
| parent | ca0eff67faaa3193ca05ee14f9d0af6797dd2a52 (diff) | |
| download | brew-d63ef14794c60464108be85cb5eeedb829261cab.tar.bz2 | |
Add DownloadError to catch a broader range of resource download errors.
Adding a broader exception class allows for errors raised in Resource.fetch
to be caught in upgrade and prevent the process from being killed when
a download fails. This should resolve issue 18364.
Fixes Homebrew/homebrew#18364.
Closes Homebrew/homebrew#26618.
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/upgrade.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/exceptions.rb | 7 | ||||
| -rw-r--r-- | Library/Homebrew/resource.rb | 12 | 
3 files changed, 17 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index a68830a94..7682922b4 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -92,6 +92,8 @@ module Homebrew extend self      e.dump      puts      Homebrew.failed = true +  rescue DownloadError => e +    ofail e    ensure      # restore previous installation state if build failed      outdated_keg.link if outdated_keg and not f.installed? rescue nil diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 66123d9f0..926407be7 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -229,6 +229,13 @@ class CompilerSelectionError < Homebrew::InstallationError    end  end +# Raised in Resource.fetch +class DownloadError < RuntimeError +  def initialize(formula) +    super "Failed to download resource for package: #{formula}" +  end +end +  # raised in CurlDownloadStrategy.fetch  class CurlDownloadStrategyError < RuntimeError; end diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 490c5dfb4..e0daf4a48 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -76,10 +76,14 @@ class Resource    # For brew-fetch and others.    def fetch -    # Ensure the cache exists -    HOMEBREW_CACHE.mkpath -    downloader.fetch -    cached_download +    begin +      # Ensure the cache exists +      HOMEBREW_CACHE.mkpath +      downloader.fetch +      cached_download +    rescue ErrorDuringExecution, CurlDownloadStrategyError => e +      raise DownloadError.new(downloader.name) +    end    end    def verify_download_integrity fn  | 
