Structured logging, error handling, and integration tests #31

Merged
qwc merged 2 commits from enhance/slog-errorhandling-integration into main 2026-02-02 17:33:03 +01:00
Owner

Summary

  • Migrate all log.Printf/log.Println calls to log/slog with structured key-value pairs across all packages (backive, cmd/backive, cmd/backive_udev, cmd/backive_ui, ui)
  • Replace panics with error returns in Database.Save(), Database.Load(), Runs.Load(), and LogToJson()
  • Fix all 5 error handling bugs in defaultCallback(): mount error checked, deferred unmount, correct error variables logged, individual backup failures use continue
  • Add retryWithBackoff() for mount/umount commands (3 attempts with exponential backoff)
  • Add SlogWriter adapter for bridging slog to cmd.Stdout/cmd.Stderr
  • Add integration tests: end-to-end backup workflow, database persistence round-trips, and config hot-reload via fsnotify
  • Tighten log file permissions from 0666 to 0640

Test plan

  • go build passes for all packages (backive, cmd/backive, cmd/backive_udev)
  • go test -v -cover passes — 48 tests, 77% coverage
  • go vet clean across all packages
  • Integration tests exercise full backup lifecycle with real temp files
  • Database persistence verified across save/load cycles
  • Config hot-reload verified via fsnotify WatchConfig

Closes #21 #25 #16 #17 #18

🤖 Generated with Claude Code

## Summary - Migrate all `log.Printf`/`log.Println` calls to `log/slog` with structured key-value pairs across all packages (backive, cmd/backive, cmd/backive_udev, cmd/backive_ui, ui) - Replace panics with error returns in `Database.Save()`, `Database.Load()`, `Runs.Load()`, and `LogToJson()` - Fix all 5 error handling bugs in `defaultCallback()`: mount error checked, deferred unmount, correct error variables logged, individual backup failures use `continue` - Add `retryWithBackoff()` for mount/umount commands (3 attempts with exponential backoff) - Add `SlogWriter` adapter for bridging slog to `cmd.Stdout`/`cmd.Stderr` - Add integration tests: end-to-end backup workflow, database persistence round-trips, and config hot-reload via fsnotify - Tighten log file permissions from 0666 to 0640 ## Test plan - [x] `go build` passes for all packages (backive, cmd/backive, cmd/backive_udev) - [x] `go test -v -cover` passes — 48 tests, 77% coverage - [x] `go vet` clean across all packages - [x] Integration tests exercise full backup lifecycle with real temp files - [x] Database persistence verified across save/load cycles - [x] Config hot-reload verified via fsnotify WatchConfig Closes #21 #25 #16 #17 #18 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Replace all log.Printf/Println calls with slog equivalents using structured
key-value pairs across all packages. Database.Save() and Database.Load() now
return errors instead of panicking. Runs.Load() returns error instead of
panicking on legacy format parse failure. LogToJson() returns error instead
of panicking on marshal failure.

Add retry with exponential backoff for mount/umount commands (3 attempts).
Add SlogWriter adapter for bridging slog to cmd.Stdout/Stderr.
Fix all 5 error handling bugs in defaultCallback: mount error checked,
defer unmount, correct error variables logged, individual backup failures
use continue.

Tighten log file permissions from 0666 to 0640.

Closes #21
Closes #25

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add integration tests for e2e workflow, database persistence, and config reload
All checks were successful
Go / build (pull_request) Successful in 5m41s
22196d3d5a
integration_test.go: Full end-to-end backup lifecycle test covering device
lookup, mount, CanRun, PrepareRun, Run, run registration, and unmount.
Also tests mount failure abort and multiple-backup continue-on-error.

database_integration_test.go: Real file I/O round-trip tests verifying
data integrity across save/load cycles and frequency scheduling behavior.

config_integration_test.go: Viper config loading from YAML temp files
with hot-reload verification via fsnotify WatchConfig.

All tests use t.TempDir() and mocks — safe to run in CI without build tags.

Closes #16
Closes #17
Closes #18

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
qwc force-pushed enhance/slog-errorhandling-integration from 22196d3d5a
All checks were successful
Go / build (pull_request) Successful in 5m41s
to 72f8d9535d
All checks were successful
Go / build (pull_request) Successful in 5m44s
2026-02-02 17:27:02 +01:00
Compare
qwc merged commit 6f1191226c into main 2026-02-02 17:33:03 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
qwc-open/backive!31
No description provided.