Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 19, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Bug Fixes

    • Error handling now reliably clears any existing response body and headers and returns status 500 when exceptions are handled, preventing leakage of prior output.
  • Tests

    • Added coverage verifying clearing of pre-existing response data and headers during exception handling; refined assertion messages.
  • Refactor

    • Internal property renamed and related docs updated for clarity; no public API changes.

@terabytesoftw terabytesoftw added the bug Something isn't working label Aug 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Warning

Rate limit exceeded

@terabytesoftw has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 13 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c17c01d and a868b3d.

📒 Files selected for processing (2)
  • src/http/ErrorHandler.php (3 hunks)
  • tests/http/ErrorHandlerTest.php (12 hunks)

Walkthrough

Renames a private property in ErrorHandler from templateResponse to response, updates internal usages and docblocks, and adds a test verifying that handleException clears an existing Response's body and headers and sets status 500 when a Response is supplied.

Changes

Cohort / File(s) Summary
ErrorHandler internals
src/http/ErrorHandler.php
Renamed private property templateResponse -> response; updated setResponse and createErrorResponse to use the new property name; adjusted docblocks and minor wording. No public API changes.
Tests
tests/http/ErrorHandlerTest.php
Added testCreateErrorResponseClearsExistingResponseData to assert that handleException clears pre-existing Response body and headers and sets status 500 when a Response is supplied; updated assertion messages (capitalization/phrasing) only.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App as Application
  participant EH as ErrorHandler
  participant R as Response

  App->>EH: handleException(Throwable)
  alt Response pre-supplied
    EH->>R: clear body
    EH->>R: remove headers
    EH->>R: set status 500
    EH->>R: write error content
  else No Response pre-supplied
    EH->>EH: create new Response
    EH->>R: set status 500 and error content
  end
  EH-->>App: return Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

I twitch my whiskers, hop with glee,
A renamed Response, tidy as can be.
Old headers vanish, body wiped clean,
Status five-oh-oh now joins the scene.
I nibble code crumbs and bound away—🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_mini_92

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (758e32f) to head (a868b3d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #107   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       320       320           
===========================================
  Files             12        12           
  Lines            810       810           
===========================================
  Hits             810       810           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/http/ErrorHandler.php (2)

51-56: Rename to $response looks fine; watch for readability due to name shadowing.

Using a private $response while also using $response as a local variable in several methods can make the code slightly harder to scan. Not blocking, but consider avoiding local-variable shadowing in future edits (e.g., $errorResponse) to improve readability.


137-147: Docblock nit: clarify the parameter description for setResponse().

The @param still refers to "Template response". Since the property was renamed and the semantics refer to any Response instance used as a base, update the param description.

Apply this diff:

-     * @param Response $response Template response with desired configuration.
+     * @param Response $response Response instance with desired configuration.
tests/http/ErrorHandlerTest.php (1)

85-90: Fix assertion message (negation missing).

The assertion uses assertNotSame, but the message states “should be …”. Flip the wording to avoid confusion.

-            "Response data should be 'Pre-existing data that should be cleared' when reusing existing response for " .
+            "Response data should not be 'Pre-existing data that should be cleared' when reusing existing response for " .
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 758e32f and 23d1cbf.

📒 Files selected for processing (2)
  • src/http/ErrorHandler.php (3 hunks)
  • tests/http/ErrorHandlerTest.php (12 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method, then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method, then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method (line 408: `$this->response = new Response($this->components['response'] ?? []);`), then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.
📚 Learning: 2025-08-03T16:24:09.241Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method (line 408: `$this->response = new Response($this->components['response'] ?? []);`), then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.

Applied to files:

  • src/http/ErrorHandler.php
📚 Learning: 2025-08-03T16:24:09.241Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#53
File: src/http/ErrorHandler.php:258-272
Timestamp: 2025-08-03T16:24:09.241Z
Learning: In yii2-extensions/psr-bridge, the StatelessApplication creates a new Response instance for each request in the reset() method, then passes it to ErrorHandler::setResponse(). This means the template response is not shared across requests, so calling clear() on it in createErrorResponse() is safe and doesn't cause side effects.

Applied to files:

  • src/http/ErrorHandler.php
🧬 Code Graph Analysis (2)
tests/http/ErrorHandlerTest.php (2)
src/http/ErrorHandler.php (3)
  • ErrorHandler (39-264)
  • setResponse (144-147)
  • handleException (113-134)
src/http/Response.php (1)
  • Response (38-150)
src/http/ErrorHandler.php (1)
src/http/Response.php (1)
  • Response (38-150)
🔇 Additional comments (4)
src/http/ErrorHandler.php (2)

63-80: Docs/readability improvement is good; implementation stays correct.

The clarification around preserving PHPUnit buffer level in tests is clear and matches the implementation. No issues found.


252-259: Using $this->response in createErrorResponse() and clearing it is correct and safe.

The method correctly reuses the provided Response or creates a new one and clears it before rendering. This aligns with the application’s lifecycle where a fresh Response is created per request and passed in, so clearing won’t cause cross-request side effects.

tests/http/ErrorHandlerTest.php (2)

63-100: Great addition: verifies that reused Response is cleared and status is set to 500.

The test effectively guards against regressions in error response initialization when reusing an existing Response.


211-211: Consistent capitalization of “Response” in assertion messages.

Minor but helpful for consistency across the suite. Looks good.

Also applies to: 233-233, 254-254, 277-277, 312-312, 335-335, 356-356, 378-378, 400-400, 421-421, 437-437, 441-441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants