Define the EntrySizeError message within the error class.
This commit is contained in:
parent
7097492dc8
commit
07eca2bae8
|
@ -711,10 +711,10 @@ module Zip
|
||||||
bytes_written += buf.bytesize
|
bytes_written += buf.bytesize
|
||||||
next unless bytes_written > size && !warned
|
next unless bytes_written > size && !warned
|
||||||
|
|
||||||
message = "entry '#{name}' should be #{size}B, but is larger when inflated."
|
error = ::Zip::EntrySizeError.new(self)
|
||||||
raise ::Zip::EntrySizeError, message if ::Zip.validate_entry_sizes
|
raise error if ::Zip.validate_entry_sizes
|
||||||
|
|
||||||
warn "WARNING: #{message}"
|
warn "WARNING: #{error.message}"
|
||||||
warned = true
|
warned = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Zip
|
||||||
class Error < StandardError; end
|
class Error < StandardError; end
|
||||||
class DestinationFileExistsError < Error; end
|
class DestinationFileExistsError < Error; end
|
||||||
class EntryNameError < Error; end
|
class EntryNameError < Error; end
|
||||||
class EntrySizeError < Error; end
|
|
||||||
|
|
||||||
class CompressionMethodError < Error
|
class CompressionMethodError < Error
|
||||||
attr_reader :compression_method
|
attr_reader :compression_method
|
||||||
|
@ -44,6 +43,19 @@ module Zip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class EntrySizeError < Error
|
||||||
|
attr_reader :entry
|
||||||
|
|
||||||
|
def initialize(entry)
|
||||||
|
super()
|
||||||
|
@entry = entry
|
||||||
|
end
|
||||||
|
|
||||||
|
def message
|
||||||
|
"Entry '#{@entry.name}' should be #{@entry.size}B, but is larger when inflated."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class SplitArchiveError < Error
|
class SplitArchiveError < Error
|
||||||
def message
|
def message
|
||||||
'Rubyzip cannot extract from split archives at this time.'
|
'Rubyzip cannot extract from split archives at this time.'
|
||||||
|
|
|
@ -139,9 +139,10 @@ class ZipFileExtractTest < MiniTest::Test
|
||||||
error = assert_raises ::Zip::EntrySizeError do
|
error = assert_raises ::Zip::EntrySizeError do
|
||||||
a_entry.extract
|
a_entry.extract
|
||||||
end
|
end
|
||||||
assert_equal \
|
assert_equal(
|
||||||
"entry 'a' should be 1B, but is larger when inflated.",
|
"Entry 'a' should be 1B, but is larger when inflated.",
|
||||||
error.message
|
error.message
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue