From 7bdaa7ffe1cd837d0f2d6c5007907534b8aaeb0e Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 16 Feb 2014 22:24:33 -0500 Subject: [PATCH] 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. --- Library/Homebrew/cmd/search.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 96bc14db30..2d83d8182d 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::Error => e + rescue GitHub::HTTPNotFoundError => e opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`" [] + rescue GitHub::Error => e + SEARCH_ERROR_QUEUE << e + [] + else + results end def search_formulae rx