-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
github: produce better curl error messages. #441
Conversation
curl_args = curl_args(args) - ["--fail"] | ||
Utils.popen_read_text(*curl_args) | ||
curl_args = curl_args(args) - ["--fail", "--silent"] | ||
Open3.popen3(*curl_args) do |_, stdout, stderr, status| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open3.popen3
in Ruby 1.8.7 unfortunately doesn't provide the fourth status
block argument, thus things will fail further up the call chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions for an API to use instead for Ruby 1.8.7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I'm not aware of a somewhat elegant solution …
We could re-implement Open3.popen3
adapting it from a more modern Ruby, as I believe all the building blocks exist, but this surely feels like a bad solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how much code is it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At most a few dozen. Mostly things like setting up pipes, then fork
and exec
with some massaging of the pipes depending on whether a block was given or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yuck. Given the imminent Ruby 2 usage I might just figure out an interim solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably lean towards using the new code for Ruby 2.0+ and falling back to Utils.popen_read_text
for older Rubies. That way most of our users will benefit from an improved error handling and we can rip out the legacy code path as soon as we enforce Ruby 2.0+. A very rough and untested sketch (that would also require some minor adjustments on the call site):
def curl_output(*args)
curl_args = curl_args(args) - ["--fail"]
if RUBY_VERSION.split(".").first.to_i >= 2
result = Open3.popen3(*curl_args) do |_, stdout, stderr, status|
[stdout.read, stderr.read, status]
end
result[0..1] + [result.last.success?]
else
output = Utils.popen_read_text(*curl_args)
[output, "(Curl error message unavailable.)", $?.success?]
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@MikeMcQuaid Since the problem in Homebrew/homebrew-core#2410 seems not to go away when the firewall is up, I wonder if there's a solution to recommend so that user isn't always looking at these error messages. For instance, do we know what port the GitHub API requires so the appropriate exception can be added to the firewall rules if desired? |
We could also recommend setting HOMEBREW_NO_GITHUB_API=1 but that feels like a sledgehammer solution since the problem may only be transient (e.g., you're using a restaurant's WiFi, which has a firewall on the relevant port, but no such problem at home) but setting a profile variable is unlikely to be unwound spontaneously by the user at some later date. |
The GitHub API uses HTTPS, so I guess we're talking about port 443. I don't think there's much we can do if this port happens to be blocked, but in this case the user typically will have quite a problematic web experience in general … |
@ilovezfs yeh, if they cannot access the GitHub API they are going to have to just disable all usage. |
Should the output say that explicitly as well as possible cause or just wait for them to file the issues and respond each time? |
@ilovezfs Sorry, you've lost me: what output/what cause? |
@MikeMcQuaid Oh, I'm only asking if you think the curl error messages will need any brew customization to make them more clear or if they're good enough all by themselves. |
@ilovezfs Good point. I think the |
@@ -30,6 +30,7 @@ | |||
) | |||
end | |||
RUBY_BIN = RUBY_PATH.dirname | |||
RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Other than the bug I found (and you already acknowledged) it behaved as I expected in local testing (e.g. when switching off WiFi or using Ruby 1.8.7). 👍 as soon as the bug is squashed. |
If we don't know why curl has failed then ensure that the error messages that it produced are included as part of the user output.
* global: add RUBY_TWO global variable. * test-bot: use RUBY_TWO global variable. * github: produce better curl error messages. If we don't know why curl has failed then ensure that the error messages that it produced are included as part of the user output.
brew tests
with your changes locally?If we don't know why curl has failed then ensure that the error messages that it produced are included as part of the user output.
Prompted by Homebrew/homebrew-core#2410. CC @ilovezfs