diff --git a/.changesets/skip--gemrc-config-during-installation-if-it-raises-an-error-loading-it.md b/.changesets/skip--gemrc-config-during-installation-if-it-raises-an-error-loading-it.md new file mode 100644 index 000000000..b1435bdb4 --- /dev/null +++ b/.changesets/skip--gemrc-config-during-installation-if-it-raises-an-error-loading-it.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "fix" +--- + +Skip the `.gemrc` config during installation if it raises an error loading it. This can be caused when the psych gem version 5 is installed on Ruby < 3.2. Use the `HTTP_PROXY` environment variable instead to configure the HTTP proxy that should be used during installation. diff --git a/ext/base.rb b/ext/base.rb index b6c757589..18f42e744 100644 --- a/ext/base.rb +++ b/ext/base.rb @@ -35,7 +35,6 @@ def report }, "download" => { "checksum" => "unverified", - "http_proxy" => http_proxy }, "build" => { "time" => Time.now.utc, @@ -55,7 +54,11 @@ def report d["libc"] = ldd_version if ldd_version end } - } + }.tap do |r| + proxy, error = http_proxy + r["download"]["http_proxy"] = proxy + r["download"]["http_proxy_error"] = error if error + end end end @@ -129,10 +132,11 @@ def download_archive(type) report["download"]["download_url"] = download_url begin + proxy, _error = http_proxy args = [ download_url, :ssl_ca_cert => CA_CERT_PATH, - :proxy => http_proxy + :proxy => proxy ] if URI.respond_to?(:open) # rubocop:disable Style/GuardClause return URI.open(*args) @@ -187,14 +191,25 @@ def store_download_version_on_report end def http_proxy - proxy = try_http_proxy_value(Gem.configuration[:http_proxy]) - return proxy if proxy + proxy, error = + begin + [try_http_proxy_value(Gem.configuration[:http_proxy]), nil] + rescue => error + # Ignore this setting if the `.gemrc` file can't be read. This raises an + # error on Rubies with psych 4 in the standard library, but also have + # psych 5 installed: Ruby < 3.2. + # https://github.com/appsignal/appsignal-ruby/issues/904 + [nil, error] + end + return [proxy, error] if proxy proxy = try_http_proxy_value(ENV["http_proxy"]) - return proxy if proxy + return [proxy, error] if proxy proxy = try_http_proxy_value(ENV["HTTP_PROXY"]) - return proxy if proxy + return [proxy, error] if proxy + + [nil, error] end def try_http_proxy_value(value)