From 59fdcfd4d0b5d68423cbcc5033ac3884b39db909 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Mon, 1 Jul 2013 16:58:16 -0500 Subject: [PATCH] Better behavior for failed connections in `brew search` Fixes Homebrew/homebrew#20868. --- Library/Homebrew/cmd/search.rb | 8 +++++++- Library/Homebrew/utils.rb | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 2ec8afd81d..ea4b655f59 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -33,7 +33,11 @@ module Homebrew extend self if count == 0 and not blacklisted? query puts "No formula found for #{query.inspect}. Searching open pull requests..." - GitHub.find_pull_requests(rx) { |pull| puts pull } + begin + GitHub.find_pull_requests(rx) { |pull| puts pull } + rescue GitHub::Error => e + opoo e.message + end end end end @@ -81,6 +85,8 @@ module Homebrew extend self end end results + rescue GitHub::Error + [] end def search_formulae rx diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 57760c3ec6..346365d775 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -261,6 +261,8 @@ end module GitHub extend self ISSUES_URI = URI.parse("https://api.github.com/legacy/issues/search/mxcl/homebrew/open/") + Error = Class.new(StandardError) + def open url, headers={}, &block default_headers = {'User-Agent' => HOMEBREW_USER_AGENT} default_headers['Authorization'] = "token #{HOMEBREW_GITHUB_API_TOKEN}" if HOMEBREW_GITHUB_API_TOKEN @@ -271,6 +273,8 @@ module GitHub extend self else raise e end + rescue SocketError => e + raise Error, "Failed to connect to: #{url}\n#{e.message}" end def each_issue_matching(query, &block)