Skip to content

Add error logging for cache deletion failures in beatrica.py #9

@chigwell

Description

@chigwell

User Story
As a software developer,
I want error logging added for cache deletion failures in beatrica/beatrica.py
so that temporary files don’t remain undeleted during error conditions.

Background
The beatrica/beatrica.py file handles cache management but currently lacks error logging for cache deletion operations. Silent failures during cache cleanup risk leaving orphaned temporary files, which could accumulate over time, consume disk space, or expose sensitive data. For example, if os.remove() or similar file operations fail due to permissions, file locks, or missing paths, the system provides no visibility into these failures. This makes debugging and monitoring cache-related issues impractical.

Acceptance Criteria

  • Modify the cache deletion logic in beatrica/beatrica.py to include error handling and logging.
  • Wrap cache deletion calls (e.g., os.remove()) in try/except blocks, catching OSError exceptions.
  • Log errors at ERROR level with contextual details (e.g., filename, error message) using Python’s logging module.
  • Ensure logged messages do not expose sensitive data but include enough information to diagnose issues (e.g., "Failed to delete temporary file [filename]: [error_str]").
  • Validate logging by simulating a cache deletion failure (e.g., deleting a file manually before the cleanup attempt) and confirming the error appears in logs.
  • Update unit tests or integration tests to verify error logging behavior when deletion fails.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions