[前][次][番号順一覧][スレッド一覧]

ruby-changes:72336

From: David <ko1@a...>
Date: Mon, 27 Jun 2022 23:36:10 +0900 (JST)
Subject: [ruby-changes:72336] f9f85a513b (master): [rubygems/rubygems] Print error messages just once in verbose mode

https://git.ruby-lang.org/ruby.git/commit/?id=f9f85a513b

From f9f85a513b9b6580dcff03872391cf387d0105b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sat, 25 Jun 2022 21:40:34 +0200
Subject: [rubygems/rubygems] Print error messages just once in verbose mode

When running a command with the `--verbose` flag that ends up raising a
`BundlerError`, Bundler will unnecessarily print the error twice.

This commit fixes the issue by removing the duplicate logging.

https://github.com/rubygems/rubygems/commit/689004a164
---
 lib/bundler/friendly_errors.rb                     |  7 ++--
 spec/bundler/bundler/friendly_errors_spec.rb       |  1 -
 .../install/gemfile/specific_platform_spec.rb      | 40 ++++++++++++++++------
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index ff6cdc4123..d0d2a6679a 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -29,8 +29,11 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/friendly_errors.rb#L29
         Bundler.ui.error error.message
         Bundler.ui.trace error.orig_exception
       when BundlerError
-        Bundler.ui.error error.message, :wrap => true
-        Bundler.ui.trace error
+        if Bundler.ui.debug?
+          Bundler.ui.trace error
+        else
+          Bundler.ui.error error.message, :wrap => true
+        end
       when Thor::Error
         Bundler.ui.error error.message
       when LoadError
diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb
index 496191f891..69fba7b826 100644
--- a/spec/bundler/bundler/friendly_errors_spec.rb
+++ b/spec/bundler/bundler/friendly_errors_spec.rb
@@ -104,7 +104,6 @@ RSpec.describe Bundler, "friendly errors" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/bundler/friendly_errors_spec.rb#L104
         expect(Bundler.ui).to receive(:error).with(error.message, :wrap => true)
         Bundler::FriendlyErrors.log_error(error)
       end
-      it_behaves_like "Bundler.ui receive trace", Bundler::BundlerError.new
     end
 
     context "Thor::Error" do
diff --git a/spec/bundler/install/gemfile/specific_platform_spec.rb b/spec/bundler/install/gemfile/specific_platform_spec.rb
index 113a0a1352..3e5a0a6270 100644
--- a/spec/bundler/install/gemfile/specific_platform_spec.rb
+++ b/spec/bundler/install/gemfile/specific_platform_spec.rb
@@ -294,17 +294,27 @@ RSpec.describe "bundle install with specific platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/specific_platform_spec.rb#L294
       gem "sorbet-static", "0.5.6433"
     G
 
-    simulate_platform "arm64-darwin-21" do
-      bundle "install", :raise_on_error => false
-    end
-
-    expect(err).to include <<~ERROR.rstrip
+    error_message = <<~ERROR.strip
       Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21' in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.
 
       The source contains the following gems matching 'sorbet-static (= 0.5.6433)':
         * sorbet-static-0.5.6433-universal-darwin-20
         * sorbet-static-0.5.6433-x86_64-linux
     ERROR
+
+    simulate_platform "arm64-darwin-21" do
+      bundle "install", :raise_on_error => false
+    end
+
+    expect(err).to include(error_message).once
+
+    # Make sure it doesn't print error twice in verbose mode
+
+    simulate_platform "arm64-darwin-21" do
+      bundle "install --verbose", :raise_on_error => false
+    end
+
+    expect(err).to include(error_message).once
   end
 
   it "does not resolve if the current platform does not match any of available platform specific variants for a transitive dependency" do
@@ -320,17 +330,27 @@ RSpec.describe "bundle install with specific platforms" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/gemfile/specific_platform_spec.rb#L330
       gem "sorbet", "0.5.6433"
     G
 
-    simulate_platform "arm64-darwin-21" do
-      bundle "install", :raise_on_error => false
-    end
-
-    expect(err).to include <<~ERROR.rstrip
+    error_message = <<~ERROR.strip
       Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21', which is required by gem 'sorbet (= 0.5.6433)', in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.
 
       The source contains the following gems matching 'sorbet-static (= 0.5.6433)':
         * sorbet-static-0.5.6433-universal-darwin-20
         * sorbet-static-0.5.6433-x86_64-linux
     ERROR
+
+    simulate_platform "arm64-darwin-21" do
+      bundle "install", :raise_on_error => false
+    end
+
+    expect(err).to include(error_message).once
+
+    # Make sure it doesn't print error twice in verbose mode
+
+    simulate_platform "arm64-darwin-21" do
+      bundle "install --verbose", :raise_on_error => false
+    end
+
+    expect(err).to include(error_message).once
   end
 
   private
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]