Inline static exception text to remove a rescue
This commit is contained in:
parent
52f3c3b9e3
commit
ca0eff67fa
@ -240,24 +240,20 @@ class ChecksumMissingError < ArgumentError; end
|
|||||||
|
|
||||||
# raised by Pathname#verify_checksum when verification fails
|
# raised by Pathname#verify_checksum when verification fails
|
||||||
class ChecksumMismatchError < RuntimeError
|
class ChecksumMismatchError < RuntimeError
|
||||||
attr_accessor :advice
|
attr_reader :expected, :hash_type
|
||||||
attr_reader :expected, :actual, :hash_type
|
|
||||||
|
|
||||||
def initialize expected, actual
|
def initialize fn, expected, actual
|
||||||
@expected = expected
|
@expected = expected
|
||||||
@actual = actual
|
|
||||||
@hash_type = expected.hash_type.to_s.upcase
|
@hash_type = expected.hash_type.to_s.upcase
|
||||||
|
|
||||||
super <<-EOS.undent
|
super <<-EOS.undent
|
||||||
#{@hash_type} mismatch
|
#{@hash_type} mismatch
|
||||||
Expected: #{@expected}
|
Expected: #{expected}
|
||||||
Actual: #{@actual}
|
Actual: #{actual}
|
||||||
|
Archive: #{fn}
|
||||||
|
To retry an incomplete download, remove the file above.
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
|
||||||
super + advice.to_s
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ResourceMissingError < ArgumentError
|
class ResourceMissingError < ArgumentError
|
||||||
|
|||||||
@ -237,7 +237,7 @@ class Pathname
|
|||||||
def verify_checksum expected
|
def verify_checksum expected
|
||||||
raise ChecksumMissingError if expected.nil? or expected.empty?
|
raise ChecksumMissingError if expected.nil? or expected.empty?
|
||||||
actual = Checksum.new(expected.hash_type, send(expected.hash_type).downcase)
|
actual = Checksum.new(expected.hash_type, send(expected.hash_type).downcase)
|
||||||
raise ChecksumMismatchError.new(expected, actual) unless expected == actual
|
raise ChecksumMismatchError.new(self, expected, actual) unless expected == actual
|
||||||
end
|
end
|
||||||
|
|
||||||
if '1.9' <= RUBY_VERSION
|
if '1.9' <= RUBY_VERSION
|
||||||
|
|||||||
@ -91,12 +91,6 @@ class Resource
|
|||||||
opoo "Cannot verify integrity of #{fn.basename}"
|
opoo "Cannot verify integrity of #{fn.basename}"
|
||||||
puts "A checksum was not provided for this resource"
|
puts "A checksum was not provided for this resource"
|
||||||
puts "For your reference the SHA1 is: #{fn.sha1}"
|
puts "For your reference the SHA1 is: #{fn.sha1}"
|
||||||
rescue ChecksumMismatchError => e
|
|
||||||
e.advice = <<-EOS.undent
|
|
||||||
Archive: #{fn}
|
|
||||||
(To retry an incomplete download, remove the file above.)
|
|
||||||
EOS
|
|
||||||
raise e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Checksum::TYPES.each do |cksum|
|
Checksum::TYPES.each do |cksum|
|
||||||
|
|||||||
@ -117,7 +117,7 @@ class ResourceTests < Test::Unit::TestCase
|
|||||||
checksum = @resource.sha1(TEST_SHA1)
|
checksum = @resource.sha1(TEST_SHA1)
|
||||||
|
|
||||||
fn.expects(:verify_checksum).with(checksum).
|
fn.expects(:verify_checksum).with(checksum).
|
||||||
raises(ChecksumMismatchError.new(checksum, Object.new))
|
raises(ChecksumMismatchError.new(fn, checksum, Object.new))
|
||||||
|
|
||||||
shutup do
|
shutup do
|
||||||
assert_raises(ChecksumMismatchError) do
|
assert_raises(ChecksumMismatchError) do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user