banger/cmd/banger/main.go
Thales Maciel a7d1a49aca
cli: restrict ExitCodeError unwrap to the CLI's own type
main.go previously unwrapped *any* error implementing `ExitCode() int`
into the process exit status, which matched *exec.ExitError too. So
whenever a CLI command ran a subprocess (mkfs.ext4, debugfs, ssh to a
daemon preflight, etc.) and that subprocess failed, the CLI would
silently exit with the subprocess's code — no error message printed.
Surfaced while bringing up `banger internal make-bundle`: mkfs.ext4
was failing on an undersized ext4 and the user saw only `EXIT=1`.

Fix: export the type as `cli.ExitCodeError` and unwrap against the
concrete type in main.go. The `ExitCode()` method is gone — only the
explicit wrap at the `vm run` command-mode call site produces this
error now.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 15:37:47 -03:00

27 lines
462 B
Go

package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"banger/internal/cli"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
cmd := cli.NewBangerCommand()
if err := cmd.ExecuteContext(ctx); err != nil {
var exitErr cli.ExitCodeError
if errors.As(err, &exitErr) {
os.Exit(exitErr.Code)
}
fmt.Fprintf(os.Stderr, "banger: %v\n", err)
os.Exit(1)
}
}