Skip to content

fix(log): guard non-Level "level" attribute against panic#559

Open
garmr-ulfr wants to merge 2 commits into
mainfrom
assert-slog-level-attr
Open

fix(log): guard non-Level "level" attribute against panic#559
garmr-ulfr wants to merge 2 commits into
mainfrom
assert-slog-level-attr

Conversation

@garmr-ulfr

@garmr-ulfr garmr-ulfr commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Hardens the radiance slog handler so a log call passing a non-slog.Level value keyed "level" can no longer panic the process.

Changes

  • fix(log): guard non-Level "level" attribute against panic — In log/log.go, the ReplaceAttr slog.LevelKey case asserted a.Value.Any().(slog.Level) without a comma-ok check. Replaced with a checked assertion; on a type mismatch the handler now emits a group (level=WARN, an error attr describing the unexpected type, and the original value preserved under a typed level-<T> key) instead of crashing.

Bug Fixes

  • Any log call passing an attribute keyed "level" with a non-slog.Level value crashed the whole process (previously hit by memmon's memory-tick log passing "level" as a string, worked around in 302a3ca by renaming the key). The handler is now panic-safe for that key regardless of the caller's value type.

Summary by CodeRabbit

  • Bug Fixes
    • Improved log level handling to avoid crashes when an unexpected value is encountered.
    • Custom log levels are now formatted more safely, and unusual values are reported in a structured way instead of causing a panic.

The slog handler asserted a.Value.Any().(slog.Level) unchecked in the
LevelKey case, panicking the process on any log call passing a non-Level
value keyed "level". Guard with a comma-ok assertion; on mismatch emit a
group (level=WARN, an error attr, and the original value under a typed
key) instead of crashing.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@garmr-ulfr, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f4f0d21e-8177-4a2d-bcb5-5436b265513d

📥 Commits

Reviewing files that changed from the base of the PR and between 2de1c18 and e0fffb2.

📒 Files selected for processing (1)
  • log/log.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch assert-slog-level-attr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens the log package’s slog handler by making ReplaceAttr resilient to callers that log a "level" attribute whose value is not a slog.Level, preventing a process panic and preserving additional context in the emitted log entry.

Changes:

  • Adds a comma-ok type assertion for "level" attributes before calling FormatLogLevel.
  • On type mismatch, emits a grouped set of attributes describing the mismatch instead of panicking.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread log/log.go Outdated
@garmr-ulfr garmr-ulfr marked this pull request as ready for review July 9, 2026 00:36
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.

2 participants