Repository navigation
chore: log API binding errors as warnings - #4452
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds 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. ChangesAPI Error Classification and Integration
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
329b3d8 to
4425875
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/errorsx/helpers_test.go (1)
13-69: ⚡ Quick winAdd handler-level tests for the new API warning path
Nice table coverage for
isAPIError. Since this PR also changesSlogHandler.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
📒 Files selected for processing (3)
pkg/errorsx/handler.gopkg/errorsx/helpers.gopkg/errorsx/helpers_test.go
4425875 to
4ae2e06
Compare
4ae2e06 to
2809081
Compare
Summary
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
Validation
Summary by CodeRabbit
New Features
Tests