Skip to content

Commit

Permalink
fix: IconifyIconLoader, add throwable callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JeRabix committed Sep 14, 2024
1 parent ec7b7d4 commit 527b204
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/Commands/DownloadIconifyIconsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
}

}
27 changes: 19 additions & 8 deletions src/IconLoaders/Iconify/IconifyIconLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,10 +46,11 @@ class IconifyIconLoader
* @param class-string<DetectorContract>[] $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,
)
{
}
Expand Down Expand Up @@ -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);
}
}
}
}

Expand Down

0 comments on commit 527b204

Please sign in to comment.