Missing error handling for invalid lock file content #4

Closed
opened 2025-11-15 03:44:09 +00:00 by snegov · 0 comments
Owner

Missing error handling for invalid lock file content

Priority: Medium
Component: backup.py
Type: Bug

Description

The lock file parsing in set_backups_lock() assumes the file contains a valid integer, but there's no error handling if the file is corrupted or contains non-numeric data.

Location

curateipsum/backup.py:114-115

Current Code

with open(lock_file_path, "r") as f:
    pid = int(f.read())

Problem

If the lock file is corrupted or empty, int() will raise a ValueError, causing the backup to crash rather than handling the situation gracefully.

Proposed Solution

try:
    with open(lock_file_path, "r") as f:
        pid = int(f.read().strip())
except (ValueError, IOError) as e:
    _lg.warning("Corrupted lock file, removing and continuing: %s", e)
    os.unlink(lock_file_path)
    return set_backups_lock(backups_dir, force)

Impact

Medium - Can cause backup process to crash if lock file is corrupted.

# Missing error handling for invalid lock file content **Priority:** Medium **Component:** backup.py **Type:** Bug ## Description The lock file parsing in `set_backups_lock()` assumes the file contains a valid integer, but there's no error handling if the file is corrupted or contains non-numeric data. ## Location `curateipsum/backup.py:114-115` ## Current Code ```python with open(lock_file_path, "r") as f: pid = int(f.read()) ``` ## Problem If the lock file is corrupted or empty, `int()` will raise a `ValueError`, causing the backup to crash rather than handling the situation gracefully. ## Proposed Solution ```python try: with open(lock_file_path, "r") as f: pid = int(f.read().strip()) except (ValueError, IOError) as e: _lg.warning("Corrupted lock file, removing and continuing: %s", e) os.unlink(lock_file_path) return set_backups_lock(backups_dir, force) ``` ## Impact **Medium** - Can cause backup process to crash if lock file is corrupted.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: snegov/cura-te-ipsum#4