From f7659b0fb3cf2b5aac9bfcbcace29c39c04b571c Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 19 Aug 2025 08:24:33 +0200 Subject: [PATCH] improve error log cases --- app/Jobs/UpdateSite.php | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/app/Jobs/UpdateSite.php b/app/Jobs/UpdateSite.php index af92c46..1ce5bcf 100644 --- a/app/Jobs/UpdateSite.php +++ b/app/Jobs/UpdateSite.php @@ -146,6 +146,13 @@ public function handle(): void // Notify users $connection->notificationSuccess(["fromVersion" => $healthResult->cms_version, "toVersion" => $this->targetVersion]); + // Done, log successful update! + $this->site->updates()->create([ + 'old_version' => $this->site->cms_version, + 'new_version' => $this->targetVersion, + 'result' => true + ]); + // Trigger site health check to write the update version back to the db CheckSiteHealth::dispatch($this->site); } @@ -193,13 +200,6 @@ protected function performExtraction(PrepareUpdate $prepareResult): void "task" => "finalizeUpdate" ] ); - - // Done, log successful update! - $this->site->updates()->create([ - 'old_version' => $this->site->cms_version, - 'new_version' => $this->targetVersion, - 'result' => true - ]); } public function failed(\Exception $exception): void @@ -212,17 +212,29 @@ public function failed(\Exception $exception): void /** @var Connection $connection */ $connection = $this->site->connection; + // Get base execption information + $failedStep = $exception instanceof UpdateException ? $exception->getStep() : null; + $failedMessage = $exception->getMessage(); + $failedTrace = $exception->getTraceAsString(); + // Notify users - $connection->notificationFailed(["fromVersion" => $this->site->cms_version, "toVersion" => $this->targetVersion]); + try { + $connection->notificationFailed(["fromVersion" => $this->site->cms_version, "toVersion" => $this->targetVersion]); + } catch (\Throwable $e) { + // If the notification fails, we have to catch the exception and combine both errors into a combined result + $failedStep .= " + notificationFailed"; + $failedMessage .= " + " . $e->getMessage(); + $failedTrace .= " + " . $e->getTraceAsString(); + } // We log any issues during the update to the DB $this->site->updates()->create([ 'old_version' => $this->site->cms_version, 'new_version' => $this->targetVersion, 'result' => false, - 'failed_step' => $exception instanceof UpdateException ? $exception->getStep() : null, - 'failed_message' => $exception->getMessage(), - 'failed_trace' => $exception->getTraceAsString() + 'failed_step' => $failedStep, + 'failed_message' => $failedMessage, + 'failed_trace' => $failedTrace ]); } }