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

Conversation

rynhndrcksn
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #53669
License MIT

During deployment some people will compile their assets with Asset Mapper then delete the root assets/ directory. This causes Asset Mapper to throw an exception, and a common work around people mentioned in the issue is to create an empty assets/ directory.

This PR makes it so the exception is only thrown while kernel.debug is equal to true, letting developers know locally that there's an issue, but allowing people to safely do this in their production environments.

@smnandre
Copy link
Contributor

With this PR, if someone runs the following command what would happen, exceptions would not be thrown if some directory is missing ?

APP_ENV=prod sf asset-map:compile

@rynhndrcksn rynhndrcksn force-pushed the fix-assetmapper-missing-assets-dir-exception branch from 79e49d8 to 962a044 Compare January 31, 2024 23:41
@rynhndrcksn
Copy link
Contributor Author

rynhndrcksn commented Feb 1, 2024

@smnandre I've attached 2 screenshots of what happens when the APP_ENV=prod symfony console asset-map:compile command is ran.

If the assets/ directory is in place, then this is the output (as expected):

APP_ENV=prod symfony console asset-map:compile being ran with an assets/ directory

If the assets/ directory is missing, then this is the output:

APP_ENV=prod symfony console asset-map:compile being ran with no assets/ directory

So during the deployment/asset compilation process people will still be notified if the assets/ directory is missing :)

@smnandre
Copy link
Contributor

smnandre commented Feb 1, 2024

@smnandre I've attached 2 screenshots of what happens when APP_ENV=prod symfony console asset-map:compile command is ran.
So during the deployment/asset compilation process people will still be notified if the assets/ directory is missing :)

Perfect for me, thank you very much 👍

@nicolas-grekas
Copy link
Member

Thank you @rynhndrcksn.

@nicolas-grekas nicolas-grekas merged commit 30a02c4 into symfony:6.4 Feb 1, 2024
9 checks passed
@@ -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.

This was referenced Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants