From 5e1ea9a7380a3679df2a5e4d474ba99dfcc97f9d Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Tue, 20 May 2025 08:06:27 -0300 Subject: [PATCH 1/8] BUFIX: deprecation_tracker breaking with unknown keywords --- CHANGELOG.md | 4 ++++ lib/deprecation_tracker.rb | 10 +++++++--- lib/next_rails/version.rb | 2 +- spec/deprecation_tracker_spec.rb | 10 ++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8f574..2e1ae58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ * Your changes/patches go here. +# v1.4.7 / 2025-05-20 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.6...v1.4.7) + +- [BUFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/156) + # v1.4.6 / 2025-04-15 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.5...v1.4.6) - [BUFIX: Fix compatibilities performance bug](https://github.com/fastruby/next_rails/pull/150) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index c7ade8d..44c184a 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -18,7 +18,7 @@ def self.callbacks @callbacks ||= [] end - def warn(*messages, uplevel: nil, category: nil) + def warn(*messages, uplevel: nil, category: nil, **kwargs) KernelWarnTracker.callbacks.each do |callback| messages.each { |message| callback.(message) } end @@ -28,7 +28,11 @@ def warn(*messages, uplevel: nil, category: nil) elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0") super(*messages, uplevel: nil) else - super + begin + super(*messages, uplevel: uplevel, category: category, **kwargs) + rescue ArgumentError => e + super(*messages, uplevel: uplevel, category: category) + end end end end @@ -43,7 +47,7 @@ def before_setup @@deprecation_tracker.bucket = test_file_name.gsub(Rails.root.to_s, ".") super end - + def after_teardown super @@deprecation_tracker.bucket = nil diff --git a/lib/next_rails/version.rb b/lib/next_rails/version.rb index e81698c..d2c1d0c 100644 --- a/lib/next_rails/version.rb +++ b/lib/next_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module NextRails - VERSION = "1.4.6" + VERSION = "1.4.7" end diff --git a/spec/deprecation_tracker_spec.rb b/spec/deprecation_tracker_spec.rb index 21d7dfe..52aa6ea 100644 --- a/spec/deprecation_tracker_spec.rb +++ b/spec/deprecation_tracker_spec.rb @@ -330,5 +330,15 @@ def self.behavior end end end + + describe "bug when warning uses unexpected keyword arguments" do + it "does not raise an error with unknown keyword args like :deprecation, :span, :stack" do + DeprecationTracker::KernelWarnTracker.callbacks << -> (message) { message.to_s } + + expect { + warn("Unknown deprecation warning", deprecation: true, span: 1.2, stack: ["line1", "line2"]) + }.to not_raise_error.and output.to_stderr + end + end end end From aff7ca00a6cced955ed37d931c24cdbb37642368 Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Wed, 28 May 2025 11:09:58 -0300 Subject: [PATCH 2/8] Keep calling super to avoid error un Ruby > 3.0 --- lib/deprecation_tracker.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index 44c184a..8dbb4b1 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -28,11 +28,7 @@ def warn(*messages, uplevel: nil, category: nil, **kwargs) elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0") super(*messages, uplevel: nil) else - begin - super(*messages, uplevel: uplevel, category: category, **kwargs) - rescue ArgumentError => e - super(*messages, uplevel: uplevel, category: category) - end + super(*messages) end end end From 9d3294ec96d89e7e4f7bc709cc4ac4e95354b72d Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Wed, 28 May 2025 11:25:06 -0300 Subject: [PATCH 3/8] Use keyword_args --- lib/deprecation_tracker.rb | 17 +++++++++++------ spec/deprecation_tracker_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index 8dbb4b1..a4d4869 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -23,12 +23,17 @@ def warn(*messages, uplevel: nil, category: nil, **kwargs) messages.each { |message| callback.(message) } end - if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0") - super(*messages) - elsif Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0") - super(*messages, uplevel: nil) - else - super(*messages) + # Build keyword args supported by this Ruby version + keyword_args = {} + keyword_args[:uplevel] = uplevel if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0") + keyword_args[:category] = category if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2.0") + + begin + # Combine known safe keywords with any extras + super(*messages, **keyword_args, **kwargs) + rescue ArgumentError + # Fallback: only pass known safe keywords + super(*messages, **keyword_args) end end end diff --git a/spec/deprecation_tracker_spec.rb b/spec/deprecation_tracker_spec.rb index 52aa6ea..330723e 100644 --- a/spec/deprecation_tracker_spec.rb +++ b/spec/deprecation_tracker_spec.rb @@ -294,6 +294,8 @@ def self.behavior end describe DeprecationTracker::KernelWarnTracker do + before { DeprecationTracker::KernelWarnTracker.callbacks.clear } + it "captures Kernel#warn" do warn_messages = [] DeprecationTracker::KernelWarnTracker.callbacks << -> (message) { warn_messages << message } @@ -340,5 +342,24 @@ def self.behavior }.to not_raise_error.and output.to_stderr end end + + it "handles known and unknown keyword arguments without raising" do + warnings = [] + DeprecationTracker::KernelWarnTracker.callbacks << ->(msg) { warnings << msg } + + expect { + warn( + "This is a test warning", + uplevel: 1, + category: :deprecated, + deprecation: true, + span: 1.2, + stack: ["line"] + ) + }.to not_raise_error + + expect(warnings).to include("This is a test warning") + end + end end From 99576c22b5eb60f66bab2689d987473f40c6e040 Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Wed, 28 May 2025 17:51:29 -0300 Subject: [PATCH 4/8] Remove CHANGELOG.md updates --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e1ae58..9f8f574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,6 @@ * Your changes/patches go here. -# v1.4.7 / 2025-05-20 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.6...v1.4.7) - -- [BUFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/156) - # v1.4.6 / 2025-04-15 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.5...v1.4.6) - [BUFIX: Fix compatibilities performance bug](https://github.com/fastruby/next_rails/pull/150) From 9a1a8dc9b297f774ee1682fb53a3ab40f2705fd4 Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Thu, 29 May 2025 08:36:26 -0300 Subject: [PATCH 5/8] Do not send keyword_args as empty {} --- lib/deprecation_tracker.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index a4d4869..a62a868 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -28,12 +28,14 @@ def warn(*messages, uplevel: nil, category: nil, **kwargs) keyword_args[:uplevel] = uplevel if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0") keyword_args[:category] = category if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2.0") - begin - # Combine known safe keywords with any extras - super(*messages, **keyword_args, **kwargs) - rescue ArgumentError - # Fallback: only pass known safe keywords - super(*messages, **keyword_args) + if keyword_args.empty? + super(*messages) + else + begin + super(*messages, **keyword_args, **kwargs) + rescue ArgumentError + super(*messages, **keyword_args) + end end end end From 806f05f294f30e80e08321868f1a0e30a7ca0933 Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Thu, 29 May 2025 13:37:41 -0300 Subject: [PATCH 6/8] Avoid using rescue --- lib/deprecation_tracker.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/deprecation_tracker.rb b/lib/deprecation_tracker.rb index a62a868..47700c8 100644 --- a/lib/deprecation_tracker.rb +++ b/lib/deprecation_tracker.rb @@ -20,22 +20,20 @@ def self.callbacks def warn(*messages, uplevel: nil, category: nil, **kwargs) KernelWarnTracker.callbacks.each do |callback| - messages.each { |message| callback.(message) } + messages.each { |message| callback.call(message) } end - # Build keyword args supported by this Ruby version - keyword_args = {} - keyword_args[:uplevel] = uplevel if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.5.0") - keyword_args[:category] = category if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.2.0") + ruby_version = Gem::Version.new(RUBY_VERSION) - if keyword_args.empty? - super(*messages) + if ruby_version >= Gem::Version.new("3.2.0") + # Kernel#warn supports uplevel, category + super(*messages, uplevel: uplevel, category: category) + elsif ruby_version >= Gem::Version.new("2.5.0") + # Kernel#warn supports only uplevel + super(*messages, uplevel: uplevel) else - begin - super(*messages, **keyword_args, **kwargs) - rescue ArgumentError - super(*messages, **keyword_args) - end + # No keyword args supported + super(*messages) end end end From 82c3e97edd918c9ff15bc664059eecf187905e1e Mon Sep 17 00:00:00 2001 From: Julio Lucero Date: Fri, 30 May 2025 08:37:55 -0300 Subject: [PATCH 7/8] Add info under unreleasd CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8f574..66818ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - [BUGFIX: example](https://github.com/fastruby/next_rails/pull/) - [CHORE: Create an entry point for the BundleReport command](https://github.com/fastruby/next_rails/pull/154) - [CHORE: Bring back support of Ruby 2.3, 2.4 and 2.5](https://github.com/fastruby/next_rails/pull/155) +- [BUFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/158) * Your changes/patches go here. From e918dfea1e986fc4b7d1c8b16f15722bcd722897 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Fri, 30 May 2025 08:20:25 -0400 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66818ad..d4317b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ - [BUGFIX: example](https://github.com/fastruby/next_rails/pull/) - [CHORE: Create an entry point for the BundleReport command](https://github.com/fastruby/next_rails/pull/154) - [CHORE: Bring back support of Ruby 2.3, 2.4 and 2.5](https://github.com/fastruby/next_rails/pull/155) -- [BUFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/158) +- [BUGFIX: deprecation_tracker breaking with unknown keywords](https://github.com/fastruby/next_rails/pull/158) * Your changes/patches go here.