Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specify exceptions for exceptions handling the vite manifest file #52169

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Illuminate/Foundation/Vite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Foundation;

use Exception;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
Expand Down Expand Up @@ -682,7 +681,7 @@ public function asset($asset, $buildDirectory = null)
* @param string|null $buildDirectory
* @return string
*
* @throws \Exception
* @throws \Illuminate\Foundation\ViteException
*/
public function content($asset, $buildDirectory = null)
{
Expand All @@ -693,7 +692,7 @@ public function content($asset, $buildDirectory = null)
$path = public_path($buildDirectory.'/'.$chunk['file']);

if (! is_file($path) || ! file_exists($path)) {
throw new Exception("Unable to locate file from Vite manifest: {$path}.");
throw new ViteException("Unable to locate file from Vite manifest: {$path}.");
}

return file_get_contents($path);
Expand Down Expand Up @@ -773,12 +772,12 @@ public function manifestHash($buildDirectory = null)
* @param string $file
* @return array
*
* @throws \Exception
* @throws \Illuminate\Foundation\ViteException
*/
protected function chunk($manifest, $file)
{
if (! isset($manifest[$file])) {
throw new Exception("Unable to locate file in Vite manifest: {$file}.");
throw new ViteException("Unable to locate file in Vite manifest: {$file}.");
}

return $manifest[$file];
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/ViteException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Illuminate\Foundation;

use Exception;

class ViteException extends Exception
{
//
}
7 changes: 4 additions & 3 deletions src/Illuminate/Foundation/ViteManifestNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Illuminate\Foundation;

use Exception;

class ViteManifestNotFoundException extends Exception
/**
* @deprecated use ViteException
*/
class ViteManifestNotFoundException extends ViteException
{
//
}
17 changes: 13 additions & 4 deletions tests/Foundation/FoundationViteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Illuminate\Tests\Foundation;

use Exception;
use Illuminate\Foundation\Vite;
use Illuminate\Foundation\ViteException;
use Illuminate\Foundation\ViteManifestNotFoundException;
use Illuminate\Support\Facades\Vite as ViteFacade;
use Illuminate\Support\Str;
use Orchestra\Testbench\TestCase;
Expand Down Expand Up @@ -564,7 +565,15 @@ public function testItCanGenerateIndividualAssetUrlInHotMode()

public function testItThrowsWhenUnableToFindAssetManifestInBuildMode()
{
$this->expectException(Exception::class);
$this->expectException(ViteException::class);
$this->expectExceptionMessage('Vite manifest not found at: '.public_path('build/manifest.json'));

ViteFacade::asset('resources/js/app.js');
}

public function testItThrowsDeprecatedExecptionWhenUnableToFindAssetManifestInBuildMode()
{
$this->expectException(ViteManifestNotFoundException::class);
$this->expectExceptionMessage('Vite manifest not found at: '.public_path('build/manifest.json'));

ViteFacade::asset('resources/js/app.js');
Expand All @@ -574,7 +583,7 @@ public function testItThrowsWhenUnableToFindAssetChunkInBuildMode()
{
$this->makeViteManifest();

$this->expectException(Exception::class);
$this->expectException(ViteException::class);
$this->expectExceptionMessage('Unable to locate file in Vite manifest: resources/js/missing.js');

ViteFacade::asset('resources/js/missing.js');
Expand Down Expand Up @@ -1232,7 +1241,7 @@ public function testItThrowsWhenUnableToFindFileToRetrieveContent()
{
$this->makeViteManifest();

$this->expectException(Exception::class);
$this->expectException(ViteException::class);
$this->expectExceptionMessage('Unable to locate file from Vite manifest: '.public_path('build/assets/app.versioned.js'));

ViteFacade::content('resources/js/app.js');
Expand Down