Skip to content

Conversation

@JacksonFergusonDev
Copy link
Owner

📝 Summary

This PR addresses several "silent failure" anti-patterns in the codebase. It introduces robust logging (full tracebacks), significantly improves the reliability of status checks using a PID file, and refactors the backup logic to be cleaner and safer.

🔍 Key Changes

1. Observability & Logging ("Errors should never pass silently")

  • Fix Tracebacks: Replaced logger.error with logger.exception in the main daemon loop to capture full stack traces during crashes.
  • Log Rotation: Increased RotatingFileHandler backup count from 1 to 5 to prevent history loss during crash loops.
  • Centralization: Refactored logging initialization into a reusable setup_logging() function.

2. Configuration & Reliability

  • PID File Management: Implemented a daemon.pid file to track the running process.
    • Before: show_status parsed launchctl/systemctl stdout (brittle).
    • After: show_status checks for the PID file and verifies the process is alive using os.kill(pid, 0).
  • Config Hardening: Config.load now explicitly catches tomllib.TOMLDecodeError and fails fast with a helpful error message instead of silently loading defaults.

3. Code Structure

  • Context Manager: Extracted the git index environment manipulation into a @temporary_index context manager.
    • Ensures pulsar_index is always cleaned up, even if the backup logic crashes.
    • Reduces indentation depth in run_backup.

4. Git Wrapper Improvements

  • Exception Propagation: Modified get_last_commit_time to raise exceptions instead of returning "Never". This allows the CLI to distinguish between a "New Repository" and a "Broken Repository" (marked as ERROR in list_repos).

✅ Checklist

  • Daemon writes PID file on startup and cleans up on exit.
  • CLI accurately reports status using PID check.
  • Malformed config files cause immediate exit (no silent defaults).
  • Logs now contain stack traces for unhandled exceptions.

@JacksonFergusonDev JacksonFergusonDev merged commit 4692166 into main Jan 31, 2026
4 checks passed
@JacksonFergusonDev JacksonFergusonDev deleted the refactor branch January 31, 2026 23:04
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.

2 participants