Skip to content

Kernel#warn: route through Warning.warn with category filtering - #462

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster32
Aug 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster32

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Kernel#warn wrote its arguments straight to $stderr and ignored the
category: and uplevel: keywords. It now builds one message — each argument on
its own line, a newline appended only when the argument does not already end with
one — and routes it through Warning.warn(message, category:), so a program that
overrides Warning.warn (or reads the category) sees it, as in MRI.

  • A String category converts to a Symbol; any other non-nil, non-Symbol value
    raises TypeError (no implicit conversion of X into Symbol).
  • A category whose warnings are disabled (Warning[category] is false) drops the
    message without calling Warning.warn; an unknown category raises the
    ArgumentError Warning.[] raises.
  • The uplevel: keyword is validated (a negative value raises ArgumentError "negative level (n)", a non-Integer a TypeError) but not acted on, as rbgo
    has no caller line to prepend.
  • No message does nothing.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%.
Zero-regression rubyspec sweep; core/kernel/warn_spec 3 → 8 and
core/warning/warn_spec 3 → 4. (The residual examples need parser-emitted
warnings to route through Warning.warn, Warning.warn arity introspection, or
the -w default the harness does not set — separate concerns.)

🤖 Generated with Claude Code

Kernel#warn wrote its arguments straight to $stderr and ignored the category:
and uplevel: keywords. It now builds one message — each argument on its own line,
a newline appended only when the argument does not already end with one — and
routes it through Warning.warn(message, category:), so a program that overrides
Warning.warn (or reads the category) sees it, as in MRI.

  - A String category is converted to a Symbol; any other non-nil, non-Symbol
    value raises TypeError ("no implicit conversion of X into Symbol").
  - A category whose warnings are disabled (Warning[category] is false) drops the
    message without calling Warning.warn; an unknown category raises the
    ArgumentError Warning.[] raises.
  - The uplevel: keyword is validated (a negative value raises ArgumentError
    "negative level (n)", a non-Integer a TypeError) but not acted on, as rbgo has
    no caller line to prepend.
  - No message does nothing.

Verified against ruby 4.0.6. Full package coverage stays at 100.0%. Zero-
regression rubyspec sweep; core/kernel/warn_spec 3 -> 8 and core/warning/warn_spec
3 -> 4. (The residual examples need parser-emitted warnings to route through
Warning.warn, Warning.warn arity introspection, or the -w default the harness does
not set — separate concerns.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit e8add9b into main Aug 26, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster32 branch August 26, 2026 12:32
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.

1 participant