From 719ce092bd81b253a1f89067bf879b2da2e9aa1e Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Mon, 16 Sep 2024 09:53:39 +0200 Subject: [PATCH 1/7] feat: Added logical failure implementation --- .../Command/ImportMapInstallCommand.php | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index 8f67656e5264e..3d0cc4f5f9fe4 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -42,18 +42,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int $finishedCount = 0; $progressBar = new ProgressBar($output); $progressBar->setFormat('%current%/%max% %bar% %url%'); - $downloadedPackages = $this->packageDownloader->downloadPackages(function (string $package, string $event, ResponseInterface $response, int $totalPackages) use (&$finishedCount, $progressBar) { - $progressBar->setMessage($response->getInfo('url'), 'url'); - if (0 === $progressBar->getMaxSteps()) { - $progressBar->setMaxSteps($totalPackages); - $progressBar->start(); - } - if ('finished' === $event) { - ++$finishedCount; - $progressBar->advance(); - } - }); + try { + $downloadedPackages = $this->packageDownloader->downloadPackages(function (string $package, string $event, ResponseInterface $response, int $totalPackages) use (&$finishedCount, $progressBar) { + $progressBar->setMessage($response->getInfo('url'), 'url'); + if (0 === $progressBar->getMaxSteps()) { + $progressBar->setMaxSteps($totalPackages); + $progressBar->start(); + } + + if ('finished' === $event) { + ++$finishedCount; + $progressBar->advance(); + } + }); + } catch (\Throwable $throwable) { + $io->error($throwable->getMessage()); + + return Command::FAILURE; + } + $progressBar->finish(); $progressBar->clear(); From f73ab5d257404d3a4441bea42055a227cc777aaf Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Mon, 16 Sep 2024 10:00:57 +0200 Subject: [PATCH 2/7] chore: Update CHANGELOG.md. --- src/Symfony/Component/AssetMapper/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/AssetMapper/CHANGELOG.md b/src/Symfony/Component/AssetMapper/CHANGELOG.md index e0b43ebb5e691..11abeaf9ad66e 100644 --- a/src/Symfony/Component/AssetMapper/CHANGELOG.md +++ b/src/Symfony/Component/AssetMapper/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 7.2 --- + * Add logical failure implementation. * Shorten the public digest of mapped assets to 7 characters 7.1 From 9831757ed59a8c97db9e80272d1ad325866bfd8a Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Mon, 16 Sep 2024 10:17:29 +0200 Subject: [PATCH 3/7] feat: only catch the LogicException since that is thrown. --- .../Component/AssetMapper/Command/ImportMapInstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index 3d0cc4f5f9fe4..0e65a0487450c 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar->advance(); } }); - } catch (\Throwable $throwable) { + } catch (\LogicException $throwable) { $io->error($throwable->getMessage()); return Command::FAILURE; From 61387107e6585068f1c1d403d8502d3e906298e6 Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Tue, 17 Sep 2024 09:23:01 +0200 Subject: [PATCH 4/7] feat: Updated global LogicException to local AssetMapper LogicException. --- .../AssetMapper/Command/ImportMapInstallCommand.php | 3 ++- .../AssetMapper/ImportMap/RemotePackageDownloader.php | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index 0e65a0487450c..0c1829d91cad6 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -11,6 +11,7 @@ namespace Symfony\Component\AssetMapper\Command; +use Symfony\Component\AssetMapper\Exception\LogicException; use Symfony\Component\AssetMapper\ImportMap\RemotePackageDownloader; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -56,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar->advance(); } }); - } catch (\LogicException $throwable) { + } catch (LogicException $throwable) { $io->error($throwable->getMessage()); return Command::FAILURE; diff --git a/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php b/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php index 47b6a14598728..56a662aa27466 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php @@ -11,6 +11,7 @@ namespace Symfony\Component\AssetMapper\ImportMap; +use Symfony\Component\AssetMapper\Exception\LogicException; use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface; use Symfony\Component\Filesystem\Filesystem; @@ -73,7 +74,7 @@ public function downloadPackages(?callable $progressCallback = null): array $downloadedPackages = []; foreach ($remoteEntriesToDownload as $package => $entry) { if (!isset($contents[$package])) { - throw new \LogicException(\sprintf('The package "%s" was not downloaded.', $package)); + throw new LogicException(\sprintf('The package "%s" was not downloaded.', $package)); } $this->remotePackageStorage->save($entry, $contents[$package]['content']); @@ -92,7 +93,7 @@ public function downloadPackages(?callable $progressCallback = null): array } if ($contents) { - throw new \LogicException(\sprintf('The following packages were unexpectedly downloaded: "%s".', implode('", "', array_keys($contents)))); + throw new LogicException(\sprintf('The following packages were unexpectedly downloaded: "%s".', implode('", "', array_keys($contents)))); } $this->saveInstalled($newInstalled); @@ -136,7 +137,7 @@ private function loadInstalled(): array } if (!isset($data['dependencies'])) { - throw new \LogicException(\sprintf('The package "%s" is missing its dependencies.', $package)); + throw new LogicException(\sprintf('The package "%s" is missing its dependencies.', $package)); } if (!isset($data['extraFiles'])) { From 1e18550e469918b3a012d0a199f1aafca35a5578 Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Thu, 26 Sep 2024 09:39:32 +0200 Subject: [PATCH 5/7] Added additional exceptions that need to be catched to resolve the actual issues. --- .../Component/AssetMapper/Command/ImportMapInstallCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index 0c1829d91cad6..e7eba5be54bf9 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -19,6 +19,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\HttpClient\Exception\TimeoutException; +use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Contracts\HttpClient\ResponseInterface; /** @@ -57,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar->advance(); } }); - } catch (LogicException $throwable) { + } catch (LogicException|TimeoutException|TransportException $throwable) { $io->error($throwable->getMessage()); return Command::FAILURE; From 95c367c14bc9c67f77935a901124e9bb2fcd6a43 Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Fri, 27 Sep 2024 13:13:20 +0200 Subject: [PATCH 6/7] fix(asset-mapper): handle exceptions in package download --- .../AssetMapper/Command/ImportMapInstallCommand.php | 2 +- .../AssetMapper/ImportMap/RemotePackageDownloader.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index e7eba5be54bf9..b26597dc3f1bf 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $progressBar->advance(); } }); - } catch (LogicException|TimeoutException|TransportException $throwable) { + } catch (LogicException $throwable) { $io->error($throwable->getMessage()); return Command::FAILURE; diff --git a/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php b/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php index 56a662aa27466..44dabdc1d2861 100644 --- a/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php +++ b/src/Symfony/Component/AssetMapper/ImportMap/RemotePackageDownloader.php @@ -14,6 +14,8 @@ use Symfony\Component\AssetMapper\Exception\LogicException; use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpClient\Exception\TimeoutException; +use Symfony\Component\HttpClient\Exception\TransportException; /** * @final @@ -70,7 +72,11 @@ public function downloadPackages(?callable $progressCallback = null): array return []; } - $contents = $this->packageResolver->downloadPackages($remoteEntriesToDownload, $progressCallback); + try { + $contents = $this->packageResolver->downloadPackages($remoteEntriesToDownload, $progressCallback); + } catch (TimeoutException|TransportException $exception) { + throw new LogicException($exception->getMessage()); + } $downloadedPackages = []; foreach ($remoteEntriesToDownload as $package => $entry) { if (!isset($contents[$package])) { From 290de5d9701bb93adc5762ab97b2b6960525739b Mon Sep 17 00:00:00 2001 From: Wouter van Marrum Date: Fri, 27 Sep 2024 13:19:38 +0200 Subject: [PATCH 7/7] fix(asset-mapper): Removed un-used use statements. --- .../Component/AssetMapper/Command/ImportMapInstallCommand.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php index b26597dc3f1bf..0c1829d91cad6 100644 --- a/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php +++ b/src/Symfony/Component/AssetMapper/Command/ImportMapInstallCommand.php @@ -19,8 +19,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\HttpClient\Exception\TimeoutException; -use Symfony\Component\HttpClient\Exception\TransportException; use Symfony\Contracts\HttpClient\ResponseInterface; /**