diff options
| author | Martin Afanasjew | 2016-07-30 14:51:14 +0200 |
|---|---|---|
| committer | Martin Afanasjew | 2016-07-30 14:51:14 +0200 |
| commit | 0a33cc591d258e07f2279bc0440d62e38983fd67 (patch) | |
| tree | 64ace017a1c178cae1f2e0aee67b4aa0d03c5674 | |
| parent | 19a77c816ebb66301b7a74fea513245043ba5aae (diff) | |
| download | brew-0a33cc591d258e07f2279bc0440d62e38983fd67.tar.bz2 | |
utils: provide a better location in 'odeprecated'
Try to find a formula in the backtrace to make the warning message more
helpful in identifying the culprit, as the formula is not always the
immediate caller of a deprecated method. Provide some sane fallbacks if
there's not formula in the call stack.
| -rw-r--r-- | Library/Homebrew/utils.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 928f25fc9..aaf9d8ba5 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -125,9 +125,18 @@ def odeprecated(method, replacement = nil, options = {}) "There is no replacement." end - # Show the first location that's not in compat. - backtrace = options[:caller] || caller - caller_message = backtrace[1] + # Try to show the most relevant location in message, i.e. (if applicable): + # - Location in a formula. + # - Location outside of 'compat/'. + # - Location of caller of deprecated method (if all else fails). + backtrace = options.fetch(:caller, caller) + caller_message = backtrace.detect do |line| + line.start_with?("#{HOMEBREW_LIBRARY}/Taps/") + end + caller_message ||= backtrace.detect do |line| + !line.start_with?("#{HOMEBREW_LIBRARY_PATH}/compat/") + end + caller_message ||= backtrace[1] message = <<-EOS.undent Calling #{method} is #{verb}! @@ -136,7 +145,7 @@ def odeprecated(method, replacement = nil, options = {}) EOS if ARGV.homebrew_developer? || options[:die] - raise FormulaMethodDeprecatedError.new message + raise FormulaMethodDeprecatedError, message else opoo "#{message}\n" end |
