Skip to content

Commit f13b6b6

Browse files
appkit-frameworkWyriHaximus
authored andcommitted
Fix handling of exceptions thrown by frame handlers
1 parent d259b44 commit f13b6b6

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

spec/generate.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,15 @@ function amqpTypeToLength(string $type, string $e): array
288288
$connectionContent .= " while ((\$frame = \$this->reader->consumeFrame(\$this->readBuffer)) !== null) {\n";
289289
$connectionContent .= " \$frameInAwaitList = false;\n";
290290
$connectionContent .= " foreach (\$this->awaitList as \$index => \$frameHandler) {\n";
291-
$connectionContent .= " if (\$frameHandler['filter'](\$frame)) {\n";
291+
$connectionContent .= " try {\n";
292+
$connectionContent .= " if (\$frameHandler['filter'](\$frame)) {\n";
293+
$connectionContent .= " unset(\$this->awaitList[\$index]);\n";
294+
$connectionContent .= " \$frameHandler['promise']->resolve(\$frame);\n";
295+
$connectionContent .= " \$frameInAwaitList = true;\n";
296+
$connectionContent .= " }\n";
297+
$connectionContent .= " } catch (Throwable \$exception) {\n";
292298
$connectionContent .= " unset(\$this->awaitList[\$index]);\n";
293-
$connectionContent .= " \$frameHandler['promise']->resolve(\$frame);\n";
299+
$connectionContent .= " \$frameHandler['promise']->reject(\$exception);\n";
294300
$connectionContent .= " \$frameInAwaitList = true;\n";
295301
$connectionContent .= " }\n";
296302
$connectionContent .= " }\n";

src/Connection.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,15 @@ public function __construct(
7070
while (($frame = $this->reader->consumeFrame($this->readBuffer)) !== null) {
7171
$frameInAwaitList = false;
7272
foreach ($this->awaitList as $index => $frameHandler) {
73-
if ($frameHandler['filter']($frame)) {
73+
try {
74+
if ($frameHandler['filter']($frame)) {
75+
unset($this->awaitList[$index]);
76+
$frameHandler['promise']->resolve($frame);
77+
$frameInAwaitList = true;
78+
}
79+
} catch (Throwable $exception) {
7480
unset($this->awaitList[$index]);
75-
$frameHandler['promise']->resolve($frame);
81+
$frameHandler['promise']->reject($exception);
7682
$frameInAwaitList = true;
7783
}
7884
}

0 commit comments

Comments
 (0)