diff --git a/src/Commands/DownloadIconifyIconsCommand.php b/src/Commands/DownloadIconifyIconsCommand.php index afcaa58..70ced14 100644 --- a/src/Commands/DownloadIconifyIconsCommand.php +++ b/src/Commands/DownloadIconifyIconsCommand.php @@ -2,6 +2,7 @@ namespace JeRabix\MoonshineIconify\Commands; +use Throwable; use JeRabix\MoonshineIconify\Detectors\DetectorContract; use JeRabix\MoonshineIconify\IconLoaders\Iconify\IconifyIconLoader; use Illuminate\Console\Command; @@ -39,9 +40,14 @@ public function handle(): void $isForce, $isDeleteNotUsedIcons, $additionalDetectors, + function (string $detectorClass, Throwable $throwable) { + $this->info("Detector $detectorClass has error: {$throwable->getMessage()}. Details in log file."); + } ); $loader->run(); + + $this->info('Icons downloaded successfully.'); } } diff --git a/src/IconLoaders/Iconify/IconifyIconLoader.php b/src/IconLoaders/Iconify/IconifyIconLoader.php index 446cf73..f5d4858 100644 --- a/src/IconLoaders/Iconify/IconifyIconLoader.php +++ b/src/IconLoaders/Iconify/IconifyIconLoader.php @@ -2,7 +2,9 @@ namespace JeRabix\MoonshineIconify\IconLoaders\Iconify; +use Closure; use Exception; +use Throwable; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Http; use JeRabix\MoonshineIconify\Detectors\DetectorContract; @@ -44,10 +46,11 @@ class IconifyIconLoader * @param class-string[] $additionalDetectors */ public function __construct( - private readonly string $scanPath, - private readonly bool $isForceLoad = false, - private readonly bool $isDeleteNotUsedIcons = true, - private readonly array $additionalDetectors = [], + private readonly string $scanPath, + private readonly bool $isForceLoad = false, + private readonly bool $isDeleteNotUsedIcons = true, + private readonly array $additionalDetectors = [], + private readonly ?Closure $detectorThrowCallback = null, ) { } @@ -104,10 +107,18 @@ private function findUsedIcons(): void $fileCode = $traverser->traverse($fileCode); foreach ($this->iconDetectors as $detector) { - $icons = array_merge( - $icons, - (new $detector($nodeFinder))->findIcons($fileCode), - ); + try { + $icons = array_merge( + $icons, + (new $detector($nodeFinder))->findIcons($fileCode), + ); + } catch (Throwable $throwable) { + report($throwable); + + if ($this->detectorThrowCallback) { + ($this->detectorThrowCallback)($detector, $throwable); + } + } } }