Repository navigation
Update the Swoole entry script - #552
klsoft-web wants to merge 1 commit into
Conversation
Reviewer's GuideDocumentationUpdate the Swoole tutorial entry script to create the PSR-7 request before handling errors and reuse the state resetter.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
| Response $response | ||
| ) use ($serverRequestFactory, $application, $errorCatcher, $container) { | ||
| ) use ($serverRequestFactory, $application, $errorCatcher, $stateResetter) { | ||
| $psr7Request = $serverRequestFactory->createFromSwoole($request); |
There was a problem hiding this comment.
🟡 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); |
There was a problem hiding this comment.
🟡 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.
Summary by Sourcery
Correct the Swoole entry script's request error handling and per-request state cleanup.
Bug Fixes:
Enhancements:
Documentation: