[rubygems/rubygems] Improve error messages in gem helpers

Previously they were printing the original command that was run, and
telling the user to rerun it. However, the command sometimes would not
match the exact command that was run (for example, when using the
`--local` flag), and in any case, it's simpler and more useful to print
the underlying error anyways.

5bc0d51b58
This commit is contained in:
David Rodríguez 2021-08-25 11:30:41 +02:00 committed by git
parent 853004e04d
commit 30b6df4144
2 changed files with 4 additions and 4 deletions

View file

@ -98,9 +98,9 @@ module Bundler
built_gem_path ||= build_gem built_gem_path ||= build_gem
cmd = [*gem_command, "install", built_gem_path.to_s] cmd = [*gem_command, "install", built_gem_path.to_s]
cmd << "--local" if local cmd << "--local" if local
_, status = sh_with_status(cmd) out, status = sh_with_status(cmd)
unless status.success? unless status.success?
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" raise("Running `#{cmd}` failed with the following output:\n\n#{out}\n")
end end
Bundler.ui.confirm "#{name} (#{version}) installed." Bundler.ui.confirm "#{name} (#{version}) installed."
end end
@ -219,7 +219,7 @@ module Bundler
out, status = sh_with_status(cmd, &block) out, status = sh_with_status(cmd, &block)
unless status.success? unless status.success?
cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin) cmd = cmd.shelljoin if cmd.respond_to?(:shelljoin)
raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out) raise("Running `#{cmd}` failed with the following output:\n\n#{out}\n")
end end
out out
end end

View file

@ -219,7 +219,7 @@ RSpec.describe Bundler::GemHelper do
FileUtils.touch app_gem_path FileUtils.touch app_gem_path
app_gem_path app_gem_path
end end
expect { subject.install_gem }.to raise_error(/Couldn't install gem/) expect { subject.install_gem }.to raise_error(/Running `#{gem_bin} install #{app_gem_path}` failed/)
end end
end end
end end