mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix: error check on state (#864)
This commit is contained in:
+9
-3
@@ -40,7 +40,9 @@ func NewManager(workspace string) *Manager {
|
||||
oldStateFile := filepath.Join(workspace, "state.json")
|
||||
|
||||
// Create state directory if it doesn't exist
|
||||
os.MkdirAll(stateDir, 0o755)
|
||||
if err := os.MkdirAll(stateDir, 0o755); err != nil {
|
||||
log.Fatalf("[FATAL] state: failed to create state directory: %v", err)
|
||||
}
|
||||
|
||||
sm := &Manager{
|
||||
workspace: workspace,
|
||||
@@ -54,13 +56,17 @@ func NewManager(workspace string) *Manager {
|
||||
if data, err := os.ReadFile(oldStateFile); err == nil {
|
||||
if err := json.Unmarshal(data, sm.state); err == nil {
|
||||
// Migrate to new location
|
||||
sm.saveAtomic()
|
||||
if err := sm.saveAtomic(); err != nil {
|
||||
log.Printf("[WARN] state: failed to save state: %v", err)
|
||||
}
|
||||
log.Printf("[INFO] state: migrated state from %s to %s", oldStateFile, stateFile)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Load from new location
|
||||
sm.load()
|
||||
if err := sm.load(); err != nil {
|
||||
log.Printf("[WARN] state: failed to load state: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return sm
|
||||
|
||||
Reference in New Issue
Block a user