Skip to content

Commit 4ca0c90

Browse files
appkit-frameworkWyriHaximus
authored andcommitted
Fix handling of exceptions thrown by frame handlers
1 parent 8258870 commit 4ca0c90

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

spec/generate.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ 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";
292-
$connectionContent .= " unset(\$this->awaitList[\$index]);\n";
293-
$connectionContent .= " \$frameHandler['promise']->resolve(\$frame);\n";
294-
$connectionContent .= " \$frameInAwaitList = true;\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";
298+
$connectionContent .= " \$frameHandler['promise']->reject(\$exception);\n";
295299
$connectionContent .= " }\n";
296300
$connectionContent .= " }\n";
297301
$connectionContent .= "\n";

src/Connection.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ 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)) {
74-
unset($this->awaitList[$index]);
75-
$frameHandler['promise']->resolve($frame);
76-
$frameInAwaitList = true;
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) {
80+
$frameHandler['promise']->reject($exception);
7781
}
7882
}
7983

0 commit comments

Comments
 (0)