Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 13 additions & 8 deletions lib/deprecation_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ def self.callbacks
@callbacks ||= []
end

def warn(*messages, uplevel: nil, category: nil)
def warn(*messages, uplevel: nil, category: nil, **kwargs)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method override now explicitly accepts both known (uplevel, category) and unknown (**kwargs) keyword arguments. This makes it compatible with upstream libraries (like sass-embedded) that may pass unexpected keys.

KernelWarnTracker.callbacks.each do |callback|
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
# 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
Expand All @@ -43,7 +48,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
Expand Down
2 changes: 1 addition & 1 deletion lib/next_rails/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module NextRails
VERSION = "1.4.6"
VERSION = "1.4.7"
end
31 changes: 31 additions & 0 deletions spec/deprecation_tracker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -330,5 +332,34 @@ 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

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