mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:41:17 +08:00
FEATURE: Improved deprecation warnings (#6722)
* FEATURE: Discourse.deprecate can report version * Ember counterpart for deprecation
This commit is contained in:
@ -602,9 +602,18 @@ module Discourse
|
||||
end
|
||||
end
|
||||
|
||||
def self.deprecate(warning)
|
||||
location = caller_locations[1]
|
||||
warning = "Deprecation Notice: #{warning}\nAt: #{location.label} #{location.path}:#{location.lineno}"
|
||||
def self.deprecate(warning, drop_from: nil, since: nil, raise_error: false)
|
||||
location = caller_locations[1].yield_self { |l| "#{l.path}:#{l.lineno}:in \`#{l.label}\`" }
|
||||
warning = ["Deprecation notice:", warning]
|
||||
warning << "(deprecated since Discourse #{since})" if since
|
||||
warning << "(removal in Discourse #{drop_from})" if drop_from
|
||||
warning << "\nAt #{location}"
|
||||
warning = warning.join(" ")
|
||||
|
||||
if raise_error
|
||||
raise Deprecation.new(warning)
|
||||
end
|
||||
|
||||
if Rails.env == "development"
|
||||
STDERR.puts(warning)
|
||||
end
|
||||
|
Reference in New Issue
Block a user