Uncruft::Warning#warn's signature doesn't match Kernel#warn
Opened this issue · 0 comments
The signature of Kernel#warn
is warn(*msgs, uplevel: nil, category: nil)
, which allows passing no arguments.
irb(main):001:0> warn
=> nil
irb(main):002:0> require 'uncruft'
=> true
irb(main):003:0> warn
/Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/uncruft-0.3.0/lib/uncruft/warning.rb:5:in `warn': wrong number of arguments (given 0, expected 1+) (ArgumentError)
from (irb):3:in `<main>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/aburgel/.rbenv/versions/3.2.2/bin/irb:25:in `<top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:492:in `exec'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:45:in `block in <top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
... 3 levels...
It does match Warning#warn
, but since we prepend Uncruft::Warning into Kernel, should it also match that signature?
I discovered this in a somewhat roundabout way. A gem in my project uses ActiveSupport::OrderedOptions
for it's configuration, one of which is named warn
. I get an ArgumentError when calling it because Uncruft handles the call and has a signature that requires an argument.
irb(main):002:0> require 'active_support'
=> true
irb(main):003:0> h = ActiveSupport::OrderedOptions.new
=> {}
irb(main):004:0> h.warn = 'blah'
=> "blah"
irb(main):005:0> h.warn
=> "blah"
irb(main):006:0> require 'uncruft'
=> true
irb(main):007:0> h.warn
/Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/uncruft-0.3.0/lib/uncruft/warning.rb:5:in `warn': wrong number of arguments (given 0, expected 1+) (ArgumentError)
from (irb):7:in `<main>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/aburgel/.rbenv/versions/3.2.2/bin/irb:25:in `<top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `load'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli/exec.rb:23:in `run'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:492:in `exec'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:34:in `dispatch'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/cli.rb:28:in `start'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/bundler-2.4.10/libexec/bundle:45:in `block in <top (required)>'
from /Users/aburgel/.rbenv/versions/3.2.2/lib/ruby/3.2.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
... 3 levels...
If you fix the signature, then you won't get an exception. But, somewhat confusingly, the behavior of ActiveSupport::OrderedOptions
still will be broken because Uncruft's warn
will take precedence. (That's because OrderedOptions
uses method_missing
.)
I think prepending Uncruft into Kernel and Object might be a little aggressive. Looking at the docs of Warning, I wonder if it's necessary. The docs suggest that you only need to extend Warning to override the default behavior.