Skip to content

Update the Swoole entry script - #552

Open
klsoft-web wants to merge 1 commit into
yiisoft:masterfrom
klsoft-web:update-swoole-entry-script
Open

klsoft-web wants to merge 1 commit into
yiisoft:masterfrom
klsoft-web:update-swoole-entry-script

Conversation

@klsoft-web

@klsoft-web klsoft-web commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Correct the Swoole entry script's request error handling and per-request state cleanup.

Bug Fixes:

  • Ensure Swoole request errors are processed with the converted PSR-7 request and reset application state after each request.

Enhancements:

  • Update the Swoole tutorial entry script to reuse its state resetter and converted request within the request handler.

Documentation:

  • Update the Swoole integration tutorial to reflect the corrected request handling flow.

@sourcery-ai

sourcery-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Documentation

Update the Swoole tutorial entry script to create the PSR-7 request before handling errors and reuse the state resetter.

  • src/guide/tutorial/using-yii-with-swoole.md L122-126 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/guide/tutorial/using-yii-with-swoole.md" line_range="116" />
<code_context>
     Response $response
-) use ($serverRequestFactory, $application, $errorCatcher, $container) {
+) use ($serverRequestFactory, $application, $errorCatcher, $stateResetter) {
+    $psr7Request = $serverRequestFactory->createFromSwoole($request);
     try {
-        $psr7Request = $serverRequestFactory->createFromSwoole($request);
</code_context>
<issue_to_address>
**Conversion errors bypass error handling**

When `createFromSwoole()` throws while converting a Swoole request, `$psr7Request` is created before the `try`, so `ErrorCatcher` never handles the throwable and `$stateResetter->reset()` is skipped; the callback escapes without sending an application error response.

Handle request conversion failures within the error-handling and cleanup path, ensuring the catch can handle them even when `$psr7Request` was not created.
</issue_to_address>

### Comment 2
<location path="src/guide/tutorial/using-yii-with-swoole.md" line_range="122" />
<code_context>
     } catch (Throwable $throwable) {
         $handler = new ThrowableHandler($throwable);
-        $psr7Response = $errorCatcher->process($request, $handler);
+        $psr7Response = $errorCatcher->process($psr7Request, $handler);
         (new SwooleResponseConverter($response))->send($psr7Response);
     }
</code_context>
<issue_to_address>
**Error handler receives the wrong request**

When a reader follows a translated Swoole example and `Application::handle()` throws, `$errorCatcher->process()` receives the native Swoole request instead of the PSR-7 request, so the error response is not rendered.

Pass the converted PSR-7 request to `$errorCatcher->process()` in the translated examples.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: src/guide/tutorial/using-yii-with-swoole.md:116, src/guide/tutorial/using-yii-with-swoole.md:122


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Response $response
) use ($serverRequestFactory, $application, $errorCatcher, $container) {
) use ($serverRequestFactory, $application, $errorCatcher, $stateResetter) {
$psr7Request = $serverRequestFactory->createFromSwoole($request);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Conversion errors bypass error handling

When createFromSwoole() throws while converting a Swoole request, $psr7Request is created before the try, so ErrorCatcher never handles the throwable and $stateResetter->reset() is skipped; the callback escapes without sending an application error response.

Handle request conversion failures within the error-handling and cleanup path, ensuring the catch can handle them even when $psr7Request was not created.

Prompt for AI agents
In `src/guide/tutorial/using-yii-with-swoole.md` at line 116:

**Conversion errors bypass error handling**

When `createFromSwoole()` throws while converting a Swoole request, `$psr7Request` is created before the `try`, so `ErrorCatcher` never handles the throwable and `$stateResetter->reset()` is skipped; the callback escapes without sending an application error response.

Handle request conversion failures within the error-handling and cleanup path, ensuring the catch can handle them even when `$psr7Request` was not created.

} catch (Throwable $throwable) {
$handler = new ThrowableHandler($throwable);
$psr7Response = $errorCatcher->process($request, $handler);
$psr7Response = $errorCatcher->process($psr7Request, $handler);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Error handler receives the wrong request

When a reader follows a translated Swoole example and Application::handle() throws, $errorCatcher->process() receives the native Swoole request instead of the PSR-7 request, so the error response is not rendered.

Pass the converted PSR-7 request to $errorCatcher->process() in the translated examples.

Prompt for AI agents
In `src/guide/tutorial/using-yii-with-swoole.md` at line 122:

**Error handler receives the wrong request**

When a reader follows a translated Swoole example and `Application::handle()` throws, `$errorCatcher->process()` receives the native Swoole request instead of the PSR-7 request, so the error response is not rendered.

Pass the converted PSR-7 request to `$errorCatcher->process()` in the translated examples.

This branch has not been deployed

No deployments
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.

1 participant