Rethrow integration log exceptions in debug mode
[MAILPOET-5568]
This commit is contained in:
@@ -32,13 +32,17 @@ class StepRunLogger {
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
private $runNumber;
|
private $runNumber;
|
||||||
|
|
||||||
|
/** @var bool */
|
||||||
|
private $isWpDebug;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AutomationRunLogStorage $automationRunLogStorage,
|
AutomationRunLogStorage $automationRunLogStorage,
|
||||||
Hooks $hooks,
|
Hooks $hooks,
|
||||||
int $runId,
|
int $runId,
|
||||||
string $stepId,
|
string $stepId,
|
||||||
string $stepType,
|
string $stepType,
|
||||||
int $runNumber
|
int $runNumber,
|
||||||
|
bool $isWpDebug = WP_DEBUG
|
||||||
) {
|
) {
|
||||||
$this->automationRunLogStorage = $automationRunLogStorage;
|
$this->automationRunLogStorage = $automationRunLogStorage;
|
||||||
$this->hooks = $hooks;
|
$this->hooks = $hooks;
|
||||||
@@ -46,6 +50,7 @@ class StepRunLogger {
|
|||||||
$this->stepId = $stepId;
|
$this->stepId = $stepId;
|
||||||
$this->stepType = $stepType;
|
$this->stepType = $stepType;
|
||||||
$this->runNumber = $runNumber;
|
$this->runNumber = $runNumber;
|
||||||
|
$this->isWpDebug = $isWpDebug;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function logStart(): void {
|
public function logStart(): void {
|
||||||
@@ -106,7 +111,10 @@ class StepRunLogger {
|
|||||||
try {
|
try {
|
||||||
$this->hooks->doAutomationStepAfterRun($log);
|
$this->hooks->doAutomationStepAfterRun($log);
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
// ignore integration errors
|
if ($this->isWpDebug) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
// ignore integration logging errors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -141,7 +141,7 @@ class StepRunLoggerTest extends MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testItCatchesAfterRunHookErrors(): void {
|
public function testItCatchesAfterRunHookErrors(): void {
|
||||||
$logger = new StepRunLogger($this->storage, $this->hooks, 1, 'step-id', AutomationRunLog::TYPE_ACTION, 1);
|
$logger = new StepRunLogger($this->storage, $this->hooks, 1, 'step-id', AutomationRunLog::TYPE_ACTION, 1, false);
|
||||||
$logs = $this->storage->getLogsForAutomationRun(1);
|
$logs = $this->storage->getLogsForAutomationRun(1);
|
||||||
$this->assertCount(0, $logs);
|
$this->assertCount(0, $logs);
|
||||||
|
|
||||||
@@ -167,6 +167,28 @@ class StepRunLoggerTest extends MailPoetTest {
|
|||||||
$this->assertLogData($logs[0], ['step_key' => 'step-key', 'status' => 'complete']);
|
$this->assertLogData($logs[0], ['step_key' => 'step-key', 'status' => 'complete']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItRethrowsAfterRunHookErrorsInDebugMode(): void {
|
||||||
|
$logger = new StepRunLogger($this->storage, $this->hooks, 1, 'step-id', AutomationRunLog::TYPE_ACTION, 1, true);
|
||||||
|
$logs = $this->storage->getLogsForAutomationRun(1);
|
||||||
|
$this->assertCount(0, $logs);
|
||||||
|
|
||||||
|
$runs = 0;
|
||||||
|
$wp = $this->diContainer->get(WordPress::class);
|
||||||
|
$wp->addAction(Hooks::AUTOMATION_RUN_LOG_AFTER_STEP_RUN, function (AutomationRunLog $log) use (&$runs) {
|
||||||
|
$runs += 1;
|
||||||
|
throw new Exception('test error');
|
||||||
|
});
|
||||||
|
|
||||||
|
$logger->logStart();
|
||||||
|
$logger->logStepData(new Step('step-id', 'action', 'step-key', [], []));
|
||||||
|
$logger->logProgress();
|
||||||
|
$this->assertSame(0, $runs);
|
||||||
|
|
||||||
|
$this->expectException(Exception::class);
|
||||||
|
$this->expectExceptionMessage('test error');
|
||||||
|
$logger->logSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
private function assertLogData(AutomationRunLog $log, array $data = []): void {
|
private function assertLogData(AutomationRunLog $log, array $data = []): void {
|
||||||
$error = isset($data['error']) ? [
|
$error = isset($data['error']) ? [
|
||||||
'message' => $data['error']->getMessage(),
|
'message' => $data['error']->getMessage(),
|
||||||
|
Reference in New Issue
Block a user