Feature #17122
closedAdd category to Warning#warn
Description
Deprecation warnings and other warnings in Ruby have a category (:deprecated, etc) but those categories aren't exposed or accessible. In the most recent Ruby 2.7 upgrade at GitHub we monkey patched Warning#warn
to be able to turn warnings into exceptions. However, there was no way to tell which warnings were deprecations and which were other types of warnings.
I want to expose the category
on the Warning
module so that I'm able to monkey patch Warning#warn
and treat deprecation warnings differently from other warnings without using a regex the strings.
Here's an example program demonstrating what I'd like to get from Ruby by implementing this feature:
module Warning
def self.warn(msg, category: nil)
if category == :deprecated
raise msg
else
super
end
end
end
def ivar
Object.new.instance_variable_get(:@ivar)
end
# Doesn't raise, but warns with verbose set
ivar
# Raises an error
Object.new.tainted?
The PR I worked on with @tenderlove is here: https://github.com/ruby/ruby/pull/3418
It moves the Warning
module to be written in Ruby, updates rb_warning_s_warn
to pass kwargs, and adds a category
to Warning#warn
.
Updated by shyouhei (Shyouhei Urabe) over 4 years ago
- Related to Feature #11588: Implement structured warnings added
Updated by shyouhei (Shyouhei Urabe) over 4 years ago
- Related to Feature #12026: Support warning processor added
Updated by shyouhei (Shyouhei Urabe) over 4 years ago
- Related to Feature #12299: Add Warning module for customized warning handling added
Updated by hsbt (Hiroshi SHIBATA) over 4 years ago
- Status changed from Open to Closed
Updated by mame (Yusuke Endoh) over 4 years ago
- Status changed from Closed to Assigned
- Assignee set to eileencodes (Eileen Uchitelle)
Updated by mame (Yusuke Endoh) over 4 years ago
- Status changed from Assigned to Closed
Updated by Eregon (Benoit Daloze) over 4 years ago
- Related to Bug #17387: About Warning.warn compatibility in Ruby 3.0.0 added
Updated by byroot (Jean Boussier) 10 months ago
- Related to Bug #20573: Warning.warn shouldn't be called for disabled warnings added