lib/sibit/bestof.rb in sibit-0.20.3 vs lib/sibit/bestof.rb in sibit-0.20.4

- old
+ new

@@ -18,10 +18,11 @@ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +require 'backtrace' require_relative 'error' require_relative 'log' # API best of. # @@ -101,17 +102,18 @@ private def best_of(method) return yield @list unless @list.is_a?(Array) results = [] + errors = [] @list.each do |api| - begin - results << yield(api) - rescue Sibit::Error => e - @log.info("The API #{api.class.name} failed at #{method}(): #{e.message}") if @verbose - end + results << yield(api) + rescue Sibit::Error => e + errors << e + @log.info("The API #{api.class.name} failed at #{method}(): #{e.message}") if @verbose end if results.empty? + errors.each { |e| @log.info(Backtrace.new(e).to_s) } raise Sibit::Error, "No APIs out of #{@list.length} managed to succeed at #{method}(): \ #{@list.map { |a| a.class.name }.join(', ')}" end results.group_by(&:to_s).values.max_by(&:size)[0] end