aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/utils')
-rw-r--r--Library/Homebrew/utils/curl.rb14
-rw-r--r--Library/Homebrew/utils/github.rb11
2 files changed, 18 insertions, 7 deletions
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb
index a1653d46c..db3534542 100644
--- a/Library/Homebrew/utils/curl.rb
+++ b/Library/Homebrew/utils/curl.rb
@@ -1,4 +1,5 @@
require "pathname"
+require "open3"
def curl_args(extra_args=[])
curl = Pathname.new ENV["HOMEBREW_CURL"]
@@ -19,6 +20,15 @@ def curl(*args)
end
def curl_output(*args)
- curl_args = curl_args(args) - ["--fail"]
- Utils.popen_read_text(*curl_args)
+ curl_args = curl_args(args)
+ curl_args -= ["--fail"]
+ if RUBY_TWO
+ curl_args -= ["--silent"]
+ Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread|
+ [stdout.read, stderr.read, wait_thread.value]
+ end
+ else
+ output = Utils.popen_read_text(*curl_args)
+ [output, nil, $?]
+ end
end
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index 36f6257f7..c5dbedd6c 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -146,7 +146,8 @@ module GitHub
args += ["--dump-header", "#{headers_tmpfile.path}"]
- output, _, http_code = curl_output(url.to_s, *args).rpartition("\n")
+ output, errors, status = curl_output(url.to_s, *args)
+ output, _, http_code = output.rpartition("\n")
output, _, http_code = output.rpartition("\n") if http_code == "000"
headers = headers_tmpfile.read
ensure
@@ -159,8 +160,8 @@ module GitHub
end
begin
- if !http_code.start_with?("2") && !$?.success?
- raise_api_error(output, http_code, headers)
+ if !http_code.start_with?("2") && !status.success?
+ raise_api_error(output, errors, http_code, headers)
end
json = Utils::JSON.load output
if block_given?
@@ -173,7 +174,7 @@ module GitHub
end
end
- def raise_api_error(output, http_code, headers)
+ def raise_api_error(output, errors, http_code, headers)
meta = {}
headers.lines.each do |l|
key, _, value = l.delete(":").partition(" ")
@@ -197,7 +198,7 @@ module GitHub
raise HTTPNotFoundError, output
else
error = Utils::JSON.load(output)["message"] rescue nil
- error ||= output
+ error ||= "curl failed! #{errors}"
raise Error, error
end
end