Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(server): enhance error handling in server patch check notifications

Andras Bacsaie005f1c83898
diff --git a/app/Jobs/ServerPatchCheckJob.php b/app/Jobs/ServerPatchCheckJob.php
index c88770d3a7..370ce86f4c 100644
--- a/app/Jobs/ServerPatchCheckJob.php
+++ b/app/Jobs/ServerPatchCheckJob.php
@@ -31,7 +31,7 @@ class ServerPatchCheckJob implements ShouldBeEncrypted, ShouldQueue
public function handle(): void
{
try {
- if ($this->server->isFunctional() === false) {
+ if ($this->server->serverStatus() === false) {
return;
}
@@ -44,6 +44,8 @@ class ServerPatchCheckJob implements ShouldBeEncrypted, ShouldQueue
$patchData = CheckUpdates::run($this->server);
if (isset($patchData['error'])) {
+ $team->notify(new ServerPatchCheck($this->server, $patchData));
+
return; // Skip if there's an error checking for updates
}
diff --git a/app/Notifications/Server/ServerPatchCheck.php b/app/Notifications/Server/ServerPatchCheck.php
index 8453e0dd6f..1686a6f37c 100644
--- a/app/Notifications/Server/ServerPatchCheck.php
+++ b/app/Notifications/Server/ServerPatchCheck.php
@@ -30,6 +30,21 @@ class ServerPatchCheck extends CustomEmailNotification
public function toMail($notifiable = null): MailMessage
{
$mail = new MailMessage;
+
+ // Handle error case
+ if (isset($this->patchData['error'])) {
+ $mail->subject("Coolify: [ERROR] Failed to check patches on {$this->server->name}");
+ $mail->view('emails.server-patches-error', [
+ 'name' => $this->server->name,
+ 'error' => $this->patchData['error'],
+ 'osId' => $this->patchData['osId'] ?? 'unknown',
+ 'package_manager' => $this->patchData['package_manager'] ?? 'unknown',
+ 'server_url' => $this->serverUrl,
+ ]);
+
+ return $mail;
+ }
+
$totalUpdates = $this->patchData['total_updates'] ?? 0;
$mail->subject("Coolify: [ACTION REQUIRED] {$totalUpdates} server patches available on {$this->server->name}");
$mail->view('emails.server-patches', [
@@ -46,6 +61,26 @@ class ServerPatchCheck extends CustomEmailNotification
public function toDiscord(): DiscordMessage
{
+ // Handle error case
+ if (isset($this->patchData['error'])) {
+ $osId = $this->patchData['osId'] ?? 'unknown';
+ $packageManager = $this->patchData['package_manager'] ?? 'unknown';
+ $error = $this->patchData['error'];
+
+ $description = "**Failed to check for updates** on server {$this->server->name}\n\n";
+ $description .= "**Error Details:**\n";
+ $description .= '• OS: '.ucfirst($osId)."\n";
+ $description .= "• Package Manager: {$packageManager}\n";
+ $description .= "• Error: {$error}\n\n";
+ $description .= "[Manage Server]($this->serverUrl)";
+
+ return new DiscordMessage(
+ title: ':x: Coolify: [ERROR] Failed to check patches on '.$this->server->name,
+ description: $description,
+ color: DiscordMessage::errorColor(),
+ );
+ }
+
$totalUpdates = $this->patchData['total_updates'] ?? 0;
$updates = $this->patchData['updates'] ?? [];
$osId = $this->patchData['osId'] ?? 'unknown';
@@ -92,6 +127,29 @@ class ServerPatchCheck extends CustomEmailNotification
public function toTelegram(): array
{
+ // Handle error case
+ if (isset($this->patchData['error'])) {
+ $osId = $this->patchData['osId'] ?? 'unknown';
+ $packageManager = $this->patchData['package_manager'] ?? 'unknown';
+ $error = $this->patchData['error'];
+
+ $message = "❌ Coolify: [ERROR] Failed to check patches on {$this->server->name}!\n\n";
+ $message .= "📊 Error Details:\n";
+ $message .= '• OS: '.ucfirst($osId)."\n";
+ $message .= "• Package Manager: {$packageManager}\n";
+ $message .= "• Error: {$error}\n\n";
+
+ return [
+ 'message' => $message,
+ 'buttons' => [
+ [
+ 'text' => 'Manage Server',
+ 'url' => $this->serverUrl,
+ ],
+ ],
+ ];
+ }
+
$totalUpdates = $this->patchData['total_updates'] ?? 0;
$updates = $this->patchData['updates'] ?? [];
$osId = $this->patchData['osId'] ?? 'unknown';
@@ -145,6 +203,31 @@ class ServerPatchCheck extends CustomEmailNotification
public function toPushover(): PushoverMessage
{
+ // Handle error case
+ if (isset($this->patchData['error'])) {
+ $osId = $this->patchData['osId'] ?? 'unknown';
+ $packageManager = $this->patchData['package_manager'] ?? 'unknown';
+ $error = $this->patchData['error'];
+
+ $message = "[ERROR] Failed to check patches on {$this->server->name}!\n\n";
+ $message .= "Error Details:\n";
+ $message .= '• OS: '.ucfirst($osId)."\n";
+ $message .= "• Package Manager: {$packageManager}\n";
+ $message .= "• Error: {$error}\n\n";
+
+ return new PushoverMessage(
+ title: 'Server patch check failed',
+ level: 'error',
+ message: $message,
+ buttons: [
+ [
+ 'text' => 'Manage Server',
+ 'url' => $this->serverUrl,
+ ],
+ ],
+ );
+ }
+
$totalUpdates = $this->patchData['total_updates'] ?? 0;
$updates = $this->patchData['updates'] ?? [];
$osId = $this->patchData['osId'] ?? 'unknown';
@@ -194,6 +277,26 @@ class ServerPatchCheck extends CustomEmailNotification
public function toSlack(): SlackMessage
{
+ // Handle error case
+ if (isset($this->patchData['error'])) {
+ $osId = $this->patchData['osId'] ?? 'unknown';
+ $packageManager = $this->patchData['package_manager'] ?? 'unknown';
+ $error = $this->patchData['error'];
+
+ $description = "Failed to check patches on '{$this->server->name}'!\n\n";
+ $description .= "*Error Details:*\n";
+ $description .= '• OS: '.ucfirst($osId)."\n";
+ $description .= "• Package Manager: {$packageManager}\n";
+ $description .= "• Error: `{$error}`\n\n";
+ $description .= "\n:link: <{$this->serverUrl}|Manage Server>";
+
+ return new SlackMessage(
+ title: 'Coolify: [ERROR] Server patch check failed',
+ description: $description,
+ color: SlackMessage::errorColor()
+ );
+ }
+
$totalUpdates = $this->patchData['total_updates'] ?? 0;
$updates = $this->patchData['updates'] ?? [];
$osId = $this->patchData['osId'] ?? 'unknown';
diff --git a/resources/views/emails/server-patches-error.blade.php b/resources/views/emails/server-patches-error.blade.php
new file mode 100644
index 0000000000..070ead4402
--- /dev/null
+++ b/resources/views/emails/server-patches-error.blade.php
@@ -0,0 +1,13 @@
+<x-emails.layout>
+Failed to check for package updates on your server {{ $name }}.
+
+## Error Details
+
+- Operating System: {{ ucfirst($osId) }}
+- Package Manager: {{ $package_manager }}
+- Error: {{ $error }}
+
+---
+
+You can manage your server and view more details in your [Coolify Dashboard]({{ $server_url }}).
+</x-emails.layout>