Conversation
nikolasdehor
left a comment
There was a problem hiding this comment.
Clean fix. These three error paths (os.MkdirAll, saveAtomic during migration, load) were silently discarding errors, which can mask permission problems or disk-full scenarios. Logging at WARN level without crashing is the right call since state initialization is best-effort during startup.
Two minor observations (non-blocking):
-
In the migration path,
sm.saveAtomic()failure is logged but the code still proceeds to log[INFO] state: migrated state from .... The migration technically failed at that point. Consider gating the INFO log:if err := sm.saveAtomic(); err != nil { log.Printf("[WARN] state: failed to save migrated state: %v", err) } else { log.Printf("[INFO] state: migrated state from %s to %s", oldStateFile, stateFile) }
-
The
load()failure log says "failed to load state" butload()may return an error for "file not found" on a fresh install, which is not really a warning. Consider checkingos.IsNotExist(err)before logging at WARN.
Neither blocks merging. LGTM.
📝 Description
Added proper error handling and logging for filesystem operations in the state manager (
pkg/state/state.go).Previously, directory creation (
os.MkdirAll), state saving during migration (sm.saveAtomic), and state loading (sm.load) were executed without checking for returned errors. This PR wraps these calls in error checks and adds[WARN]logs to ensure that any filesystem issues (like permission errors or disk space issues) are properly surfaced instead of failing silently.🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
if err := ...; err != nilchecks ensures operators are immediately notified of underlying environment issues via logs without necessarily crashing the application.🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
(Expected log output if a failure occurs)
[WARN] state: failed to create state directory: permission denied☑️ Checklist