diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-09-23 22:41:09 +0200 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-09-23 22:41:09 +0200 |
commit | 751641649580f544e92311e1aafeea8e158a36e1 (patch) | |
tree | 6755ea57c2fa1da3abf313020e5c58c03ab39ff5 | |
parent | 3260d5994ec33bfaf81162c61d0d20bfff023375 (diff) | |
download | bundler-add_info_to_some_deprecation_messages.tar.gz |
Add caller information to some deprecation messagesadd_info_to_some_deprecation_messages
Some deprecations would be fixed more easily if they included the
location where the deprecated method was called.
-rw-r--r-- | lib/bundler.rb | 14 | ||||
-rw-r--r-- | lib/bundler/shared_helpers.rb | 7 | ||||
-rw-r--r-- | spec/other/major_deprecation_spec.rb | 14 |
3 files changed, 24 insertions, 11 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index a21dc7726d..4321a7ed3d 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -116,7 +116,7 @@ module Bundler end def environment - SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load" + SharedHelpers.major_deprecation 2, "Bundler.environment has been removed in favor of Bundler.load", :print_caller_location => true load end @@ -282,7 +282,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`", + :print_caller_location => true ) unbundled_env @@ -321,7 +322,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`", + :print_caller_location => true ) with_env(unbundled_env) { yield } @@ -342,7 +344,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ - "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`", + :print_caller_location => true ) with_env(unbundled_env) { Kernel.system(*args) } @@ -363,7 +366,8 @@ EOF Bundler::SharedHelpers.major_deprecation( 2, "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ - "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`", + :print_caller_location => true ) with_env(unbundled_env) { Kernel.exec(*args) } diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index e6e2b79344..dc44f8345c 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -124,7 +124,12 @@ module Bundler namespace.const_get(constant_name) end - def major_deprecation(major_version, message) + def major_deprecation(major_version, message, print_caller_location: false) + if print_caller_location + caller_location = caller_locations(2, 2).first + message = "#{message} (called at #{caller_location.path}:#{caller_location.lineno})" + end + bundler_major_version = Bundler.bundler_major_version if bundler_major_version > major_version require_relative "errors" diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index d1e3cf87f4..ec2cdbf99e 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -20,7 +20,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_env", :bundler => "2" do expect(deprecations).to include \ "`Bundler.clean_env` has been deprecated in favor of `Bundler.unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.original_env` " \ + "(called at -e:1)" end pending "is removed and shows a helpful error message about it", :bundler => "3" @@ -35,7 +36,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_env", :bundler => "2" do expect(deprecations).to include( "`Bundler.with_clean_env` has been deprecated in favor of `Bundler.with_unbundled_env`. " \ - "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env`" + "If you instead want the environment before bundler was originally loaded, use `Bundler.with_original_env` " \ + "(called at -e:1)" ) end @@ -51,7 +53,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_system", :bundler => "2" do expect(deprecations).to include( "`Bundler.clean_system` has been deprecated in favor of `Bundler.unbundled_system`. " \ - "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system`" + "If you instead want to run the command in the environment before bundler was originally loaded, use `Bundler.original_system` " \ + "(called at -e:1)" ) end @@ -67,7 +70,8 @@ RSpec.describe "major deprecations" do it "is deprecated in favor of .unbundled_exec", :bundler => "2" do expect(deprecations).to include( "`Bundler.clean_exec` has been deprecated in favor of `Bundler.unbundled_exec`. " \ - "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec`" + "If you instead want to exec to a command in the environment before bundler was originally loaded, use `Bundler.original_exec` " \ + "(called at -e:1)" ) end @@ -81,7 +85,7 @@ RSpec.describe "major deprecations" do end it "is deprecated in favor of .load", :bundler => "2" do - expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load" + expect(deprecations).to include "Bundler.environment has been removed in favor of Bundler.load (called at -e:1)" end pending "is removed and shows a helpful error message about it", :bundler => "3" |