aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2014-02-16 22:24:33 -0500
committerJack Nagel2014-02-16 23:19:09 -0500
commit7bdaa7ffe1cd837d0f2d6c5007907534b8aaeb0e (patch)
tree9a53db8f6e0329c20f01dc4b73c1752a7b564cb4
parentea7415237c33744a00c6b27aebfa42416a0b01d1 (diff)
downloadbrew-7bdaa7ffe1cd837d0f2d6c5007907534b8aaeb0e.tar.bz2
search: use a queue to collect errors
The threading in the tap search code makes handling errors difficult. If an API-related error is raised in one thread, it is likely to be raised in each of the rest as well. This results in duplicated error messages, which is ugly and bad UX. This patch adds a synchronized queue to collect these exceptions. The first one added to the queue is re-raised after all operations are complete. It's not ideal, but it's minimally invasive and I don't have the energy or time to do a rewrite.
-rw-r--r--Library/Homebrew/cmd/search.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 96bc14db3..2d83d8182 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -1,9 +1,12 @@
require 'formula'
require 'blacklist'
require 'utils'
+require 'thread'
module Homebrew extend self
+ SEARCH_ERROR_QUEUE = Queue.new
+
# A regular expession to capture the username (one or more char but no `/`,
# which has to be escaped like `\/`), repository, followed by an optional `/`
# and an optional query.
@@ -64,10 +67,12 @@ module Homebrew extend self
begin
GitHub.print_pull_requests_matching(query)
rescue GitHub::Error => e
- opoo e.message
+ SEARCH_ERROR_QUEUE << e
end
end
end
+
+ raise SEARCH_ERROR_QUEUE.pop unless SEARCH_ERROR_QUEUE.empty?
end
SEARCHABLE_TAPS = [
@@ -115,12 +120,14 @@ module Homebrew extend self
end
end
end
- results
- rescue GitHub::RateLimitExceededError => e
+ rescue GitHub::HTTPNotFoundError => e
+ opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[]
rescue GitHub::Error => e
- opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
+ SEARCH_ERROR_QUEUE << e
[]
+ else
+ results
end
def search_formulae rx