-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: dump body directly if json indent fails #643
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe changes in this pull request modify the Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #643 +/- ##
==========================================
+ Coverage 92.70% 92.72% +0.01%
==========================================
Files 22 22
Lines 4879 4891 +12
==========================================
+ Hits 4523 4535 +12
Misses 308 308
Partials 48 48 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
humatest/humatest.go (1)
348-351
: Consider adding debug logging for indent failures.For better debugging capabilities, consider logging the indentation error when it occurs. This would help diagnose issues where the JSON formatting unexpectedly fails.
Here's a suggested improvement:
- if err := json.Indent(buf, b, "", " "); err != nil { - // Indent failed, so just write the buffer. - buf.Write(b) + if err := json.Indent(buf, b, "", " "); err != nil { + // Log the error for debugging purposes + fmt.Printf("JSON indent failed: %v\n", err) + // Fall back to writing the raw buffer + buf.Write(b)🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 349-351: humatest/humatest.go#L349-L351
Added lines #L349 - L351 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
humatest/humatest.go
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
humatest/humatest.go
[warning] 349-351: humatest/humatest.go#L349-L351
Added lines #L349 - L351 were not covered by tests
🔇 Additional comments (1)
humatest/humatest.go (1)
348-351
: LGTM! The error handling improvement looks good.
The change correctly handles JSON indentation failures by falling back to the raw buffer content, which aligns with the PR objective.
Let's verify the behavior with some test cases. Run this script to check if we have any existing tests for invalid JSON:
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 349-351: humatest/humatest.go#L349-L351
Added lines #L349 - L351 were not covered by tests
if err := json.Indent(buf, b, "", " "); err != nil { | ||
// Indent failed, so just write the buffer. | ||
buf.Write(b) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding test coverage for the error path.
The new error handling code is currently not covered by tests. Consider adding test cases for:
- Invalid JSON that fails indentation
- Malformed JSON with special characters
Would you like me to help generate test cases for these scenarios?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 349-351: humatest/humatest.go#L349-L351
Added lines #L349 - L351 were not covered by tests
Small fix for when the JSON is invalid (or not actually JSON). This makes sure it is still put into the response rather than accidentally dropped.
Summary by CodeRabbit
DumpRequest
function, enhancing the robustness of the error handling process.