Skip to content

Commit 1bc1f86

Browse files
Anton Shabovtazloyuser
authored andcommitted
Bad action call error added
1 parent d6467c0 commit 1bc1f86

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/Exception/BadActionCall.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* This file is part of PHPinnacle/Ensign.
4+
*
5+
* (c) PHPinnacle Team <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
declare(strict_types = 1);
12+
13+
namespace PHPinnacle\Ensign\Exception;
14+
15+
final class BadActionCall extends EnsignException
16+
{
17+
/**
18+
* @param int $step
19+
* @param \Exception $error
20+
*/
21+
public function __construct(int $step, \Exception $error)
22+
{
23+
parent::__construct(sprintf('Bad action call at step "%d".', $step), 0, $error);
24+
}
25+
}

src/Kernel.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Amp\Coroutine;
1414
use Amp\LazyPromise;
15+
use PHPinnacle\Ensign\Exception\BadActionCall;
1516
use PHPinnacle\Identity\UUID;
1617

1718
final class Kernel
@@ -82,6 +83,8 @@ private function adapt($value, Token $token)
8283
*/
8384
private function recoil(\Generator $generator, Token $token)
8485
{
86+
$step = 1;
87+
8588
while ($generator->valid()) {
8689
$token->guard();
8790

@@ -90,14 +93,29 @@ private function recoil(\Generator $generator, Token $token)
9093

9194
$generator->send(yield $this->adapt($value, $token));
9295
} catch (\Exception $error) {
93-
/** @scrutinizer ignore-call */
94-
$generator->throw($error);
96+
$this->throw($generator, $error, $step);
97+
} finally {
98+
$step++;
9599
}
96100
}
97101

98102
return $this->adapt($generator->getReturn(), $token);
99103
}
100104

105+
/**
106+
* @param \Generator $generator
107+
* @param \Exception $error
108+
* @param int $step
109+
*/
110+
private function throw(\Generator $generator, \Exception $error, int $step)
111+
{
112+
try {
113+
$generator->throw($error);
114+
} catch (\Throwable $error) {
115+
throw new BadActionCall($step, $error);
116+
}
117+
}
118+
101119
/**
102120
* @param int|string $key
103121
* @param mixed $value

0 commit comments

Comments
 (0)