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

[AssetMapper] Fix exception if assets directory is missing in production #53701

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
param('kernel.project_dir'),
abstract_arg('array of excluded path patterns'),
abstract_arg('exclude dot files'),
param('kernel.debug'),
])

->set('asset_mapper.public_assets_path_resolver', PublicAssetsPathResolver::class)
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Component/AssetMapper/AssetMapperRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(
private readonly string $projectRootDir,
private readonly array $excludedPathPatterns = [],
private readonly bool $excludeDotFiles = true,
private readonly bool $debug = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set this to true by default in aa469d9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I did that locally while my project was set to prod mode, it causes Symfony to crash and return a 500 error.

Screenshot of a 500 internal server error

Is it possible that param('kernel.debug'), (link to line) isn't passing in false when the site is in prod mode, making AssetMapperRepository.php default to true, making it so the $this->debug checks succeed while the site is in prod mode?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can still use the prod environment in debug mode if you want locally. The prod environment defaults to non-debug mode, but the APP_DEBUG env variable still wins over this default.

) {
}

Expand Down Expand Up @@ -147,7 +148,7 @@ private function getDirectories(): array
$this->absolutePaths = [];
foreach ($this->paths as $path => $namespace) {
if ($filesystem->isAbsolutePath($path)) {
if (!file_exists($path)) {
if (!file_exists($path) && $this->debug) {
throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
}
$this->absolutePaths[realpath($path)] = $namespace;
Expand All @@ -161,7 +162,9 @@ private function getDirectories(): array
continue;
}

throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
if ($this->debug) {
throw new \InvalidArgumentException(sprintf('The asset mapper directory "%s" does not exist.', $path));
}
}

return $this->absolutePaths;
Expand Down