Skip to content

chore: log API binding errors as warnings - #4452

Merged
turip merged 1 commit into
mainfrom
chore/fix-api-error-logging-level
May 27, 2026
Merged

turip merged 1 commit into
mainfrom
chore/fix-api-error-logging-level

Conversation

@turip

@turip turip commented May 27, 2026 •

Copy link
Copy Markdown
Member

Summary

  • classify generated legacy and v3 API binding errors in errorsx
  • log those API binding errors at warning level from the shared slog error handler
  • add coverage for direct, wrapped, and joined API errors

Why

These errors are request/API binding failures caused by invalid client input. They are expected warning-level events rather than server failures, so the handler should log them as warnings instead of errors.

Affected errors

  • UnescapedCookieParamError
  • UnmarshalingParamError
  • RequiredParamError
  • RequiredHeaderError
  • InvalidParamFormatError
  • TooManyValuesForParamError

Validation

  • go test ./pkg/errorsx
  • go vet ./pkg/errorsx

Summary by CodeRabbit

  • New Features

    • API errors are now detected more reliably (including wrapped and combined cases) and are logged as warnings earlier to reduce noise and prevent duplicate/error cascades.
  • Tests

    • Added unit tests validating API error detection across legacy and current API types, wrapped errors, combined errors, and nil/non-API cases.

Review Change Stack

@turip
turip requested a review from a team as a code owner May 27, 2026 21:42
@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b58a0633-04c8-4ddc-b400-a161ad0d8a63

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae2e06 and 2809081.

📒 Files selected for processing (3)
  • pkg/errorsx/handler.go
  • pkg/errorsx/helpers.go
  • pkg/errorsx/helpers_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/errorsx/helpers.go
  • pkg/errorsx/handler.go
  • pkg/errorsx/helpers_test.go

📝 Walkthrough

Walkthrough

Adds helpers that detect errors originating from API packages (including wrapped and joined errors), uses that detection in SlogHandler to log such errors as warnings (early return), and adds unit tests validating detection across wrapping scenarios.

Changes

API Error Classification and Integration

Layer / File(s) Summary
API error classification helpers and validation
pkg/errorsx/helpers.go, pkg/errorsx/helpers_test.go
apiErrorPackages captures api and apiv3 error package paths. isAPIError delegates to isErrorFromPackages, which inspects concrete types (stripping pointer wrappers), and recursively unwraps single and multi-error chains to check package origin. Tests cover nil, direct API errors, wrapped (%w), joined (errors.Join), and non-API errors.
Handler early-return for API errors
pkg/errorsx/handler.go
SlogHandler.Handle and SlogHandler.HandleContext now check isAPIError(err) and log matching errors with Warn/WarnContext, returning early before existing warn/context-cancel handling and default error logging.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: logging API binding errors at warning level instead of error level.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/fix-api-error-logging-level

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 and usage tips.

@turip turip added release-note/misc Miscellaneous changes area/api labels May 27, 2026
@turip
turip force-pushed the chore/fix-api-error-logging-level branch from 329b3d8 to 4425875 Compare May 27, 2026 21:44

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/errorsx/helpers_test.go (1)

13-69: ⚡ Quick win

Add handler-level tests for the new API warning path

Nice table coverage for isAPIError. Since this PR also changes SlogHandler.HandleContext, please add tests that assert API errors are logged as warnings and short-circuit before the error path.

As per coding guidelines **/*_test.go: Make sure the tests are comprehensive and cover the changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/errorsx/helpers_test.go` around lines 13 - 69, Add handler-level tests
exercising SlogHandler.HandleContext to assert that when a handler returns an
API error (use api.InvalidParamFormatError and apiv3.InvalidParamFormatError
instances used in isAPIError tests) the handler path short-circuits: the logger
emits a warning (not an error) and the error-path logic is not executed.
Implement tests that (1) install a test logger/recorder into a SlogHandler, (2)
run HandleContext with a handler func that returns an API error and with a
separate handler/path that would record if the error-path ran (e.g., set a
flag), and (3) assert the logger captured a warning message containing the error
and that the error-path flag was not set; repeat for wrapped/joined API errors
to match isAPIError cases. Ensure tests live alongside helpers_test.go and
reference SlogHandler.HandleContext and isAPIError behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/errorsx/handler.go`:
- Around line 59-62: Handle currently logs API errors at error level while
HandleContext downgrades them to warnings; update Handle to apply the same
policy: detect API errors using isAPIError(err) and call h.Logger.Warn (or
WarnContext without ctx) instead of h.Logger.Error so API errors are logged as
warnings; ensure the same error path used in HandleContext (the isAPIError
check) is mirrored in Handle and that non-API errors continue to be logged as
errors.

---

Nitpick comments:
In `@pkg/errorsx/helpers_test.go`:
- Around line 13-69: Add handler-level tests exercising
SlogHandler.HandleContext to assert that when a handler returns an API error
(use api.InvalidParamFormatError and apiv3.InvalidParamFormatError instances
used in isAPIError tests) the handler path short-circuits: the logger emits a
warning (not an error) and the error-path logic is not executed. Implement tests
that (1) install a test logger/recorder into a SlogHandler, (2) run
HandleContext with a handler func that returns an API error and with a separate
handler/path that would record if the error-path ran (e.g., set a flag), and (3)
assert the logger captured a warning message containing the error and that the
error-path flag was not set; repeat for wrapped/joined API errors to match
isAPIError cases. Ensure tests live alongside helpers_test.go and reference
SlogHandler.HandleContext and isAPIError behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c0b76f08-c549-48b2-bac2-bb93ae0896e4

📥 Commits

Reviewing files that changed from the base of the PR and between 9260e5f and 329b3d8.

📒 Files selected for processing (3)
  • pkg/errorsx/handler.go
  • pkg/errorsx/helpers.go
  • pkg/errorsx/helpers_test.go

Comment thread pkg/errorsx/handler.go Resolved
@turip
turip force-pushed the chore/fix-api-error-logging-level branch from 4425875 to 4ae2e06 Compare May 27, 2026 21:48
@turip
turip force-pushed the chore/fix-api-error-logging-level branch from 4ae2e06 to 2809081 Compare May 27, 2026 21:59
@turip
turip enabled auto-merge (squash) May 27, 2026 22:03
@turip
turip disabled auto-merge May 27, 2026 22:03
@turip
turip merged commit 4620bee into main May 27, 2026
25 checks passed
@turip
turip deleted the chore/fix-api-error-logging-level branch May 27, 2026 22:03

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved.

This branch was previously deployed

1 inactive deployment
dev — 28090816 Deployed May 27, 2026 by turip via Migration Checks #14699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants