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

Do not load config from empty cache file #46

Open
wants to merge 1 commit into
base: 1.16.x
Choose a base branch
from

Conversation

settermjd
Copy link

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

This change solves a fatal error that I've been encountering, whenever the cache file is present, but empty:

Fatal error: Uncaught TypeError: Cannot assign int to property Laminas\ConfigAggregator\ConfigAggregator::$config of type array in /var/www/vendor/laminas/laminas-config-aggregator/src/ConfigAggregator.php:260

So, this change returns false in loadConfigFromCache() if the config file is present but is also empty.

@settermjd settermjd added the Bug Something isn't working label Jun 19, 2024
@settermjd settermjd self-assigned this Jun 19, 2024
@settermjd settermjd force-pushed the do-not-load-cache-from-empty-cache-file branch from 41e67e2 to f21e955 Compare June 19, 2024 01:38
This change solves a fatal error that I've been encountering, whenever
the cache file is present, but empty:

Uncaught TypeError: Cannot assign int to property
Laminas\ConfigAggregator\ConfigAggregator::$config of type array

So, this change returns false if the config file is present but empty.

Signed-off-by: Matthew Setter <[email protected]>
@settermjd settermjd force-pushed the do-not-load-cache-from-empty-cache-file branch from f21e955 to 3d200e8 Compare June 19, 2024 01:40
file_put_contents($this->cacheFile, '');
$aggregator = new ConfigAggregator([], $this->cacheFile);

self::assertEmpty($aggregator->getMergedConfig());
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this assert an array that matches the input configuration? i.e. self::assertSame([], $aggregator->getMergedConfig()); - also, when the cache file is empty, do we expect the cache file to be updated with the now cached config?

Copy link
Author

Choose a reason for hiding this comment

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

Good question, @gsteel. I'll take another look tonight.

@boesing
Copy link
Member

boesing commented Jun 20, 2024

Do we know why there is an empty cache file in the first place?
I mean, we implemented @michalbundyra FileWriter to actually ensure that the file is written in a "safe" way.
If that is not "safe" (anymore, or never was, I have no clue), we should consider a more reliable way of persisting cache configuration files as empty files shouldn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants