Standardize error handling: use FatalError in compact.go, sync.go, migrate.go

Replace direct fmt.Fprintf(os.Stderr, "Error:...") + os.Exit(1) patterns with
FatalError() and FatalErrorWithHint() helpers for consistent error handling.

Files updated:
- compact.go: All 48 os.Exit(1) calls converted
- sync.go: All error patterns converted (kept 1 valid summary exit)
- migrate.go: Partial conversion (4 patterns converted)

This is incremental progress on bd-qioh. Remaining work: ~326 error patterns
across other cmd/bd files.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-23 13:45:14 -08:00
parent 05f37d2408
commit 03b12e4b4b
3 changed files with 94 additions and 195 deletions

View File

@@ -74,11 +74,10 @@ This command:
"error": "no_beads_directory",
"message": "No .beads directory found. Run 'bd init' first.",
})
} else {
fmt.Fprintf(os.Stderr, "Error: no .beads directory found\n")
fmt.Fprintf(os.Stderr, "Hint: run 'bd init' to initialize bd\n")
}
os.Exit(1)
} else {
FatalErrorWithHint("no .beads directory found", "run 'bd init' to initialize bd")
}
}
// Load config to get target database name (respects user's config.json)
@@ -103,10 +102,10 @@ This command:
"error": "detection_failed",
"message": err.Error(),
})
os.Exit(1)
} else {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
FatalError("%v", err)
}
os.Exit(1)
}
if len(databases) == 0 {
@@ -174,14 +173,15 @@ This command:
"message": "Multiple old database files found",
"databases": formatDBList(oldDBs),
})
os.Exit(1)
} else {
fmt.Fprintf(os.Stderr, "Error: multiple old database files found:\n")
for _, db := range oldDBs {
fmt.Fprintf(os.Stderr, " - %s (version: %s)\n", filepath.Base(db.path), db.version)
}
fmt.Fprintf(os.Stderr, "\nPlease manually rename the correct database to %s and remove others.\n", cfg.Database)
os.Exit(1)
}
os.Exit(1)
} else if currentDB != nil && currentDB.version != Version {
// Update version metadata
needsVersionUpdate = true