-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Catch and wrap up failures in applying compensation steps
- Loading branch information
Showing
5 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
|
||
namespace MeadSteve\Tale\Exceptions; | ||
|
||
use Throwable; | ||
|
||
class FailedApplyingAllCompensations extends \RuntimeException implements TaleException | ||
{ | ||
/** | ||
* @var Throwable[] | ||
*/ | ||
public $caughtExceptions; | ||
|
||
/** | ||
* FailedApplyingAllCompensations constructor. | ||
* @param \Throwable[] $caughtExceptions | ||
*/ | ||
public function __construct($caughtExceptions) | ||
{ | ||
$previous = null; | ||
if (sizeof($caughtExceptions) == 1) { | ||
$previous = $caughtExceptions[0]; | ||
} | ||
parent::__construct("Failed applying all compensation steps", 0, $previous); | ||
$this->caughtExceptions = $caughtExceptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace MeadSteve\Tale\Tests\Steps\Mocks; | ||
|
||
use MeadSteve\Tale\Steps\NamedStep; | ||
|
||
class StepWithFailingCompensate implements NamedStep | ||
{ | ||
public function execute($state) | ||
{ | ||
return $state; | ||
} | ||
|
||
/** | ||
* @param mixed $state | ||
* @throws \Exception | ||
*/ | ||
public function compensate($state): void | ||
{ | ||
throw new \Exception("I failed compensating"); | ||
} | ||
|
||
/** | ||
* @return string the public name of this step | ||
*/ | ||
public function stepName(): string | ||
{ | ||
return "step with failing compensation"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters