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.
This commit is contained in:
parent
19a77c816e
commit
0a33cc591d
@ -125,9 +125,18 @@ def odeprecated(method, replacement = nil, options = {})
|
|||||||
"There is no replacement."
|
"There is no replacement."
|
||||||
end
|
end
|
||||||
|
|
||||||
# Show the first location that's not in compat.
|
# Try to show the most relevant location in message, i.e. (if applicable):
|
||||||
backtrace = options[:caller] || caller
|
# - Location in a formula.
|
||||||
caller_message = backtrace[1]
|
# - 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
|
message = <<-EOS.undent
|
||||||
Calling #{method} is #{verb}!
|
Calling #{method} is #{verb}!
|
||||||
@ -136,7 +145,7 @@ def odeprecated(method, replacement = nil, options = {})
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
if ARGV.homebrew_developer? || options[:die]
|
if ARGV.homebrew_developer? || options[:die]
|
||||||
raise FormulaMethodDeprecatedError.new message
|
raise FormulaMethodDeprecatedError, message
|
||||||
else
|
else
|
||||||
opoo "#{message}\n"
|
opoo "#{message}\n"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user