Skip to content

Conversation

julioalucero
Copy link

@julioalucero julioalucero commented May 20, 2025

STJ-23: BUGFIX: deprecation_tracker breaking with unknown keywords

Description

BUGFIX: Prevent DeprecationTracker from crashing when receiving unknown keyword arguments.

In certain environments (e.g. when using sass-embedded), the warn method receives unexpected keyword arguments such as :deprecation, :span, or :stack. Previously, these unrecognized keywords would raise an ArgumentError and interrupt execution. This patch safely handles unknown keyword arguments while preserving known ones.

Motivation and Context

Fixes #152 — DeprecationTracker was breaking during setup in projects using sass-embedded due to unhandled keyword arguments in warn.

This update ensures that warn forwards all known and unknown keyword arguments safely to super, and gracefully falls back to known keywords if the parent method does not accept extras.

How Has This Been Tested?

  • Added a test to verify that warn can accept unknown keyword arguments (e.g. :deprecation, :span, :stack) without raising errors.
  • Ran the full test suite using Ruby 2.7 and Ruby 3.2 to ensure backward and forward compatibility.
  • Verified that the warn method continues to capture and store deprecation messages as expected.

Screenshots:

I will abide by the code of conduct

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.

else
super
begin
super(*messages, uplevel: uplevel, category: category, **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 forwards all keyword arguments — both expected (uplevel, category) and any extras like :deprecation, :span, etc. — to super. If the superclass doesn't accept extra keywords, we fall back to known ones to avoid breaking.

super
begin
super(*messages, uplevel: uplevel, category: category, **kwargs)
rescue ArgumentError => e
Copy link
Author

Choose a reason for hiding this comment

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

Some logging implementations (e.g., in native gems) may not accept arbitrary keyword args. This fallback ensures compatibility by only passing the known, expected keys.

@hmdros hmdros changed the title BUFIX: deprecation_tracker breaking with unknown keywords BUGFIX: deprecation_tracker breaking with unknown keywords May 22, 2025
@julioalucero julioalucero changed the title BUGFIX: deprecation_tracker breaking with unknown keywords STJ-20: BUGFIX: deprecation_tracker breaking with unknown keywords May 22, 2025
@julioalucero julioalucero changed the title STJ-20: BUGFIX: deprecation_tracker breaking with unknown keywords STJ-23: BUGFIX: deprecation_tracker breaking with unknown keywords May 22, 2025
@JuanVqz
Copy link
Member

JuanVqz commented May 22, 2025

@julioalucero I'd like to merge #156 first to check from ruby 2.3+ to make sure your changes are compatible with older rubies first.

And please do not use the release/ prefix on your branch; we usually do releases in their own PRs/commits. Thanks!

@julioalucero
Copy link
Author

Moving here #157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] NextRails deprecation_tracker breaking with unknown keywords:
2 participants