Use Throwable instead of \Exception

[MAILPOET-4463]
This commit is contained in:
John Oleksowicz
2022-09-12 12:55:00 -05:00
committed by Jan Jakeš
parent 2c2f15a562
commit 8cbbe5aa6e
3 changed files with 9 additions and 8 deletions

View File

@ -124,14 +124,14 @@ class StepHandler {
try {
$this->stepRunners[$stepType]->run($step, $workflow, $workflowRun);
$log->markCompletedSuccessfully();
} catch (\Exception $e) {
} catch (Throwable $e) {
$log->markFailed();
$log->addError($e);
throw $e;
} finally {
try {
$this->hooks->doWorkflowStepAfterRun($log);
} catch (Exception $e) {
} catch (Throwable $e) {
$log->addError($e);
}
$this->workflowRunLogStorage->createWorkflowRunLog($log);

View File

@ -4,6 +4,7 @@ namespace MailPoet\Automation\Engine\Data;
use DateTimeImmutable;
use MailPoet\Automation\Engine\Utils\Json;
use Throwable;
class WorkflowRunLog {
@ -131,13 +132,13 @@ class WorkflowRunLog {
$this->completedAt = new DateTimeImmutable();
}
public function addError(\Exception $exception, string $userFacingMessage = ''): void {
public function addError(Throwable $error, string $userFacingMessage = ''): void {
$error = [
'message' => $exception->getMessage(),
'exceptionClass' => get_class($exception),
'message' => $error->getMessage(),
'errorClass' => get_class($error),
'userFacingMessage' => $userFacingMessage,
'code' => $exception->getCode(),
'trace' => $exception->getTrace(),
'code' => $error->getCode(),
'trace' => $error->getTrace(),
];
$this->errors[] = $error;

View File

@ -143,7 +143,7 @@ class WorkflowRunLogTest extends \MailPoetTest {
$error = $log->getErrors()[0];
expect($error['message'])->equals('error');
expect($error['code'])->equals(12345);
expect($error['exceptionClass'])->equals('Exception');
expect($error['errorClass'])->equals('Exception');
expect($error['trace'])->array();
expect(count($error['trace']))->greaterThan(0);
}