beads/cmd/bd/setup/exit.go
beads/crew/wickham 4102096666 refactor: standardize error handling with FatalError wrappers (bd-qioh)
Convert ~250 instances of direct fmt.Fprintf(os.Stderr)+os.Exit(1)
to FatalError/FatalErrorWithHint/FatalErrorRespectJSON across 54 files.

Complex multi-line messages, warnings, loop-internal errors, and
JSON-branching patterns intentionally preserved where the helpers
do not fit cleanly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-21 16:27:09 -08:00

24 lines
745 B
Go

package setup
import (
"fmt"
"os"
)
// setupExit is used by setup commands to exit the process. Tests can stub this.
var setupExit = os.Exit
// FatalError writes an error message to stderr and exits with code 1.
// This mirrors the main package's FatalError but uses the testable setupExit.
func FatalError(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "Error: "+format+"\n", args...)
setupExit(1)
}
// FatalErrorWithHint writes an error message with a hint to stderr and exits.
// This mirrors the main package's FatalErrorWithHint but uses the testable setupExit.
func FatalErrorWithHint(message, hint string) {
fmt.Fprintf(os.Stderr, "Error: %s\n", message)
fmt.Fprintf(os.Stderr, "Hint: %s\n", hint)
setupExit(1)
}