From 91c5ddb2bd91e840a7fd73217b33b665fa05bdfb Mon Sep 17 00:00:00 2001 From: Boy132 Date: Wed, 22 Apr 2026 13:52:31 +0200 Subject: [PATCH] Catch icon exception when importing egg (#2299) --- app/Models/Traits/HasIcon.php | 2 +- app/Services/Eggs/Sharing/EggImporterService.php | 13 +++++++++---- lang/en/admin/egg.php | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Models/Traits/HasIcon.php b/app/Models/Traits/HasIcon.php index 293082249..b8693d081 100644 --- a/app/Models/Traits/HasIcon.php +++ b/app/Models/Traits/HasIcon.php @@ -49,7 +49,7 @@ trait HasIcon }; if (is_null($normalizedExtension)) { - throw new Exception(trans('admin/egg.import.unknown_extension')); + throw new Exception(trans('admin/egg.import.unknown_extension', ['extension' => $extension])); } $fileName = static::getIconStoragePath() . "/$this->uuid.$normalizedExtension"; diff --git a/app/Services/Eggs/Sharing/EggImporterService.php b/app/Services/Eggs/Sharing/EggImporterService.php index 68f0b9010..23f46f20e 100644 --- a/app/Services/Eggs/Sharing/EggImporterService.php +++ b/app/Services/Eggs/Sharing/EggImporterService.php @@ -6,6 +6,7 @@ use App\Enums\EggFormat; use App\Exceptions\Service\InvalidFileUploadException; use App\Models\Egg; use App\Models\EggVariable; +use Exception; use Illuminate\Database\ConnectionInterface; use Illuminate\Http\UploadedFile; use Illuminate\Support\Arr; @@ -268,11 +269,15 @@ class EggImporterService return; } - $extension = strtolower($matches[1]); - $data = base64_decode($matches[2]); + try { + $extension = strtolower($matches[1]); + $data = base64_decode($matches[2]); - if ($data) { - $egg->writeIcon($extension, $data); + if ($data) { + $egg->writeIcon($extension, $data); + } + } catch (Exception $exception) { + report($exception); } } diff --git a/lang/en/admin/egg.php b/lang/en/admin/egg.php index c135598c0..d70886ff8 100644 --- a/lang/en/admin/egg.php +++ b/lang/en/admin/egg.php @@ -30,7 +30,7 @@ return [ 'no_local_ip' => 'Local IP Addresses are not allowed', 'unsupported_format' => 'Unsupported Format. Supported Formats: :formats', 'invalid_url' => 'The provided URL is invalid', - 'unknown_extension' => 'Unknown icon extension', + 'unknown_extension' => 'Unknown icon extension (:extension)', 'could_not_write' => 'Could not write icon to disk', 'icon_deleted' => 'Icon Deleted', 'no_icon' => 'No Icon Provided',