From 8b51cf019d56c6ab5ab03c7bb4cf504eb7659c93 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Mon, 29 Dec 2014 22:52:53 -0500 Subject: [PATCH] Move exception text into exception object --- Library/Homebrew/download_strategy.rb | 7 +------ Library/Homebrew/exceptions.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index f474b03a63..55097a92af 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -184,12 +184,7 @@ class CurlDownloadStrategy < AbstractDownloadStrategy had_incomplete_download = false retry else - if @url =~ %r[^file://] - msg = "File does not exist: #{@url.sub(%r[^file://], "")}" - else - msg = "Download failed: #{@url}" - end - raise CurlDownloadStrategyError, msg + raise CurlDownloadStrategyError.new(@url) end end ignore_interrupts { temporary_path.rename(cached_location) } diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index a6a3380bb1..66d5c33d2f 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -208,7 +208,16 @@ class DownloadError < RuntimeError end # raised in CurlDownloadStrategy.fetch -class CurlDownloadStrategyError < RuntimeError; end +class CurlDownloadStrategyError < RuntimeError + def initialize(url) + case url + when %r[^file://(.+)] + super "File does not exist: #{$1}" + else + super "Download failed: #{url}" + end + end +end # raised by safe_system in utils.rb class ErrorDuringExecution < RuntimeError