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

Fix trying to open non-existant manifest file #1600

Merged
merged 1 commit into from
Jul 3, 2024
Merged

Fix trying to open non-existant manifest file #1600

merged 1 commit into from
Jul 3, 2024

Conversation

AirBair
Copy link
Contributor

@AirBair AirBair commented Jun 30, 2024

Q A
Branch? 2.x
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets
License MIT
Doc

Hello,

Following #1529, cache:clear auto-script in fresh composer install for example is crashing because the manifest.json does not exist yet.

image

This PR add a check on the existence of the file before trying to open it.

Copy link
Member

@dbu dbu left a comment

Choose a reason for hiding this comment

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

thanks for looking into this. i suggest to explicitly check for the file to have better error reporting.

@@ -68,7 +68,7 @@ public function process(ContainerBuilder $container): void
$runtimeDefinition->setArgument(1, $version);

if (is_a($versionStrategyDefinition->getClass(), JsonManifestVersionStrategy::class, true)) {
$jsonManifestString = file_get_contents($version);
$jsonManifestString = @file_get_contents($version);
Copy link
Member

Choose a reason for hiding this comment

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

i really dislike ignoring errors. could we instead do

Suggested change
$jsonManifestString = @file_get_contents($version);
if (!file_exists($version)) {
$this->log($container, 'The manifest file at "'.$version.'" does not yet exist');
return;
}
$jsonManifestString = file_get_contents($version);

Copy link
Contributor Author

@AirBair AirBair Jul 3, 2024

Choose a reason for hiding this comment

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

I didn't add it in the first place because file_get_contents doesn't trigger an error, only a E_WARNING which doesn't halt the script. It's the cache:clear of symfony who transform this into an error afterwards.

And since $jsonManifestString is set to false with or without the error control operator, the unreadable file is handled by the next condition.

But as you wish, the log message will be clearer with your proposed solution !

Copy link
Member

Choose a reason for hiding this comment

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

yeah, i guess the check if the contents of the file is empty would have caught it. but this seems clearer to me.

thanks for looking into the issue and providing the fix!

@dbu
Copy link
Member

dbu commented Jul 3, 2024

/cc @wouterSkepp

@coveralls
Copy link

Coverage Status

coverage: 81.835%. remained the same
when pulling 91d8823 on AirBair:patch-1
into 0c95437 on liip:2.x.

@AirBair AirBair changed the title Add error control operator on JsonManifestVersionStrategy Fix trying to open non-existant manifest file Jul 3, 2024
@dbu dbu merged commit b8dbc57 into liip:2.x Jul 3, 2024
15 checks passed
@dbu
Copy link
Member

dbu commented Jul 3, 2024

tagged as https://github.com/liip/LiipImagineBundle/releases/tag/2.13.1

@coveralls
Copy link

Coverage Status

coverage: 81.746% (-0.09%) from 81.835%
when pulling 9a11026 on AirBair:patch-1
into 0c95437 on liip:2.x.

@AirBair AirBair deleted the patch-1 branch July 3, 2024 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants