Skip to content

Fix ArgumentError when Warning.process is used again

Peter Leitzen requested to merge pl-fix-log-deprecations-initializer into master

What does this MR do and why?

This MR fixes an ArgumentError raised after Warning.process is used twice.

Consider this:

require 'warning'

Warning.process(/foo/) { :raise }
Warning.process(/bar/) { :raise }
# => ArgumentError (comparison of Regexp with Regexp failed)

The first argument of Warning.process must be a path and actions can be passed as a Hash:

require 'warning'

Warning.process('', /foo/ => :raise)
Warning.process('', /bar/ => :raise)
warn("foo") # => RuntimeError (foo)
warn("bar") # => RuntimeError (bar)

There's an upstream GitHub issue that discusses this problem: https://github.com/jeremyevans/ruby-warning/issues/17 (closed) and the fix https://github.com/jeremyevans/ruby-warning/pull/19 (merged).

How to set up and validate locally

On master do:

  • bundle exec rails console
  • Warning.process('') { :raise }
  • 💥 ArgumentError: comparison of Regexp with String failed

On pl-fix-log-deprecations-initializer do:

  • bundle exec rails console
  • Warning.process('') { :raise }
  • Verify via warn 'anything' to raise RuntimeError: anything

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports