Skip to content

Commit 90c90ad

Browse files
Merge pull request #8232 from rubygems/deivid-rodriguez/openssl-original-error
Include original error when openssl fails to load
2 parents 3b5854a + 440343b commit 90c90ad

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

bundler/lib/bundler/fetcher.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ def initialize(remote_uri)
3737
# This is the error raised when a source is HTTPS and OpenSSL didn't load
3838
class SSLError < HTTPError
3939
def initialize(msg = nil)
40-
super msg || "Could not load OpenSSL.\n" \
41-
"You must recompile Ruby with OpenSSL support."
40+
super "Could not load OpenSSL.\n" \
41+
"You must recompile Ruby with OpenSSL support.\n" \
42+
"original error: #{msg}\n"
4243
end
4344
end
4445

@@ -251,7 +252,13 @@ def connection
251252
needs_ssl = remote_uri.scheme == "https" ||
252253
Bundler.settings[:ssl_verify_mode] ||
253254
Bundler.settings[:ssl_client_cert]
254-
raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
255+
if needs_ssl
256+
begin
257+
require "openssl"
258+
rescue StandardError, LoadError => e
259+
raise SSLError.new(e.message)
260+
end
261+
end
255262

256263
con = Gem::Net::HTTP::Persistent.new name: "bundler", proxy: :ENV
257264
if gem_proxy = Gem.configuration[:http_proxy]

bundler/spec/install/gems/compact_index_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,14 @@ def require(*args)
738738
end
739739
end
740740

741-
it "explains what to do to get it" do
741+
it "explains what to do to get it, and includes original error" do
742742
gemfile <<-G
743743
source "#{source_uri.gsub(/http/, "https")}"
744744
gem "myrack"
745745
G
746746

747747
bundle :install, env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false, artifice: nil
748-
expect(err).to include("OpenSSL")
748+
expect(err).to include("recompile Ruby").and include("cannot load such file")
749749
end
750750
end
751751

bundler/spec/install/gems/dependency_api_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,14 +707,14 @@ def require(*args)
707707
end
708708
end
709709

710-
it "explains what to do to get it" do
710+
it "explains what to do to get it, and includes original error" do
711711
gemfile <<-G
712712
source "#{source_uri.gsub(/http/, "https")}"
713713
gem "myrack"
714714
G
715715

716716
bundle :install, artifice: "fail", env: { "RUBYOPT" => opt_add("-I#{bundled_app("broken_ssl")}", ENV["RUBYOPT"]) }, raise_on_error: false
717-
expect(err).to include("OpenSSL")
717+
expect(err).to include("recompile Ruby").and include("cannot load such file")
718718
end
719719
end
720720

0 commit comments

Comments
 (0)