diff options
author | Bundlerbot <bot@bundler.io> | 2019-09-27 05:36:29 +0000 |
---|---|---|
committer | David RodrÃguez <deivid.rodriguez@riseup.net> | 2019-11-07 16:41:30 +0100 |
commit | a7bb0f9a8a5e80b3e537b9f549705f7802ddef5c (patch) | |
tree | 7891d5d18ab068615f0c6769d619fa25ec4bd9c0 | |
parent | c75a1cda94bdf8ffd18c51a0a23dc3cdcaa1718c (diff) | |
download | bundler-a7bb0f9a8a5e80b3e537b9f549705f7802ddef5c.tar.gz |
Merge #7361
7361: Add caller information to some deprecation messages r=indirect a=deivid-rodriguez
### What was the end-user problem that led to this PR?
The problem was that some deprecations mention usage of deprecated methods, but include no information about where the deprecated method is being called.
### What was your diagnosis of the problem?
My diagnosis was that we should include this information with this kind of deprecation messages, to make migration easier.
### What is your fix for the problem, implemented in this PR?
My fix is to add an optional argument to the `major_deprecation` method, to print the location of the deprecated caller.
### Why did you choose this fix out of the possible options?
I chose this fix because it required little code changes.
Co-authored-by: David RodrÃguez <deivid.rodriguez@riseup.net>
(cherry picked from commit e719a58b26e2f85c885a950d90c8d4a0f7339c0f)
-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" |