Skip to content

fix: add error handling for corrupted cache files in FileHandler - #9586

Merged
michalsn merged 1 commit into
codeigniter4:developfrom
michalsn:fix/cache-get
May 31, 2025
Merged

fix: add error handling for corrupted cache files in FileHandler#9586
michalsn merged 1 commit into
codeigniter4:developfrom
michalsn:fix/cache-get

Conversation

@michalsn

Copy link
Copy Markdown
Member

Description
This PR fixes the FileHandler::getItem() method to gracefully manage corrupted or malformed cache files that cannot be read or unserialized.

  • unserialize() is now wrapped in a try/catch block, since it may throw a Throwable that the @ operator cannot suppress
  • file_get_contents() and unlink() are prefixed with @ to suppress warnings, as these functions only emit warnings and do not throw exceptions

Fixes#9573

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsnmichalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label May 27, 2025
@whiskey-coder

Copy link
Copy Markdown

can you add error log. when content is false

@michalsn

Copy link
Copy Markdown
MemberAuthor

Since this is a caching library, corrupted or unreadable files are expected edge cases, and logging every occurrence could easily flood logs in high-traffic environments. Silent failure is acceptable here, as cache misses are non-critical by design.

@michalsn
michalsn merged commit acb5470 into codeigniter4:developMay 31, 2025
@michalsn

Copy link
Copy Markdown
MemberAuthor

Thanks everyone!

@michalsn
michalsn deleted the fix/cache-get branch May 31, 2025 17:58
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugVerified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Unhandled False in FileHandler

4 participants

@michalsn@whiskey-coder@paulbalandan@ddevsr