summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Zimmerman <[email protected]>2024-03-25 15:53:53 -0700
committergit <[email protected]>2024-03-28 15:54:33 +0000
commit97b2cc34359968459a6eba2ac166f3650adf47be (patch)
treef0a1ca072924c844966fda2603677a476811976e
parentfa0a62413ab9bdf72855a6614835174f50f29474 (diff)
Allow FormatError to take either String or Gem for source
Most of the calls to `FormatError.new` pass `@gem` for the second argument, which has a `path` method. But in one case—on package.rb:691 in `verify_gz`, the `source` argument is a `String`. So if there's ever a GZip decode error when attempting to read the contents of the `data.tar.gz` file, instead of reporting the underlying GZip error (which might be something like "unexpected end of file"), we would report instead a NoMethodError coming from package.rb ``` Exception while verifying sorbet-0.5.11301.gem ERROR: While executing gem ... (NoMethodError) undefined method `path' for "data.tar.gz":String @path = source.path ^^^^^ ``` There are two ways to fix this: 1. Make `FormatError#initialize` aware of the fact that `source` might sometimes be a `String` 2. Make the call to `FormatError.new` in `verify_gz` pass `@gem` instead of `entry.full_name`. I've chosen 1 because I think it's more useful to see "unexpected end of file in data.tar.gz" instead of "unexpected end of file in sorbet-0.5.11301.gem." The end of file **is actually** in data.tar.gz, not in the gem file itself, which was decoded successfully.
-rw-r--r--lib/rubygems/package.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index 72a179da37..1d5d764237 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -59,7 +59,7 @@ class Gem::Package
def initialize(message, source = nil)
if source
- @path = source.path
+ @path = source.is_a?(String) ? source : source.path
message += " in #{path}" if path
end