aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils.rb
diff options
context:
space:
mode:
authorJack Nagel2014-06-24 20:59:26 -0500
committerJack Nagel2014-06-24 21:01:04 -0500
commit2daabe9863bd430a696020419d3534d22cac9fbb (patch)
tree8367304f0745c977901b6e6d131c628fda50ff15 /Library/Homebrew/utils.rb
parent3d69e5ab7b4d8e3f97fe9fea102a4c53687de3e6 (diff)
downloadbrew-2daabe9863bd430a696020419d3534d22cac9fbb.tar.bz2
Fix uninitialized constant error in GitHub.open
The error handling depends on side effects of `require "net/https"`, so it should be wrapped in an explicit begin block. cf. Homebrew/homebrew#30407.
Diffstat (limited to 'Library/Homebrew/utils.rb')
-rw-r--r--Library/Homebrew/utils.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index ab186eedd..6684b3696 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -311,15 +311,18 @@ module GitHub extend self
}
default_headers['Authorization'] = "token #{HOMEBREW_GITHUB_API_TOKEN}" if HOMEBREW_GITHUB_API_TOKEN
- Kernel.open(url, default_headers.merge(headers)) do |f|
- yield Utils::JSON.load(f.read)
+
+ begin
+ Kernel.open(url, default_headers.merge(headers)) do |f|
+ yield Utils::JSON.load(f.read)
+ end
+ rescue OpenURI::HTTPError => e
+ handle_api_error(e)
+ rescue SocketError, OpenSSL::SSL::SSLError => e
+ raise Error, "Failed to connect to: #{url}\n#{e.message}", e.backtrace
+ rescue Utils::JSON::Error => e
+ raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
end
- rescue OpenURI::HTTPError => e
- handle_api_error(e)
- rescue SocketError, OpenSSL::SSL::SSLError => e
- raise Error, "Failed to connect to: #{url}\n#{e.message}", e.backtrace
- rescue Utils::JSON::Error => e
- raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace
end
def handle_api_error(e)