From c8a219a84bf72717c18e2cf0339cb617bced6e0f Mon Sep 17 00:00:00 2001 From: Bjoern Kalkbrenner Date: Tue, 1 Dec 2026 13:21:10 +0100 Subject: [PATCH] solutions: exit 3 is "interrupted", "not found" moves to 7 The family convention (docs/program-conventions.md) gives 3 to a command stopped by SIGINT/SIGTERM (owner decision 2026-12-01 to unify). A cancelled context now exits 3; yetano-solutions also stops on SIGTERM. Co-Authored-By: Claude Opus 5.5 --- solutions/cli/cli.go | 19 +++++++++++++------ solutions/cli/cli_test.go | 19 +++++++++++++++++++ solutions/cmd/yetano-solutions/main.go | 3 ++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/solutions/cli/cli.go b/solutions/cli/cli.go index 93d15e5..7a8061b 100644 --- a/solutions/cli/cli.go +++ b/solutions/cli/cli.go @@ -23,13 +23,17 @@ import ( "yetano.dev/yetano/core/solutions/store" ) -// Exit codes, the same as yet's (yet/internal/cliutil). +// Exit codes, the same as yet's (yet/internal/cliutil). 0-3 are the +// family-wide ones (docs/program-conventions.md in the meta-repo); 3 is +// "interrupted" there, so "not found" is 7 (owner decision 2026-12-01, +// it was 3 up to solutions/v0.1.0). const ( - ExitOK = 0 - ExitError = 1 - ExitUsage = 2 - ExitNotFound = 3 - ExitConflict = 4 + ExitOK = 0 + ExitError = 1 + ExitUsage = 2 + ExitInterrupted = 3 // stopped by SIGINT/SIGTERM (the context was cancelled) + ExitConflict = 4 + ExitNotFound = 7 ) // Env is what the embedding program provides. @@ -103,6 +107,9 @@ func Run(ctx context.Context, args []string, env Env) int { code = ee.code } switch { + case ctx.Err() != nil: + // whatever failed, it failed because we were told to stop + code = ExitInterrupted case errors.Is(err, engine.ErrNotFound), errors.Is(err, store.ErrNotFound): code = ExitNotFound case errors.Is(err, engine.ErrModified): diff --git a/solutions/cli/cli_test.go b/solutions/cli/cli_test.go index 9304fbf..04342d0 100644 --- a/solutions/cli/cli_test.go +++ b/solutions/cli/cli_test.go @@ -147,3 +147,22 @@ func TestInteractiveWizard(t *testing.T) { t.Error("export did not write the configuration") } } + +// Ctrl-C: a cancelled context is exit 3, the family-wide "interrupted" +// (docs/program-conventions.md); "not found" moved to 7 for it. +func TestInterrupted(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + var out, errb bytes.Buffer + code := Run(ctx, []string{"solution", "show", "nope"}, Env{ + Stdin: strings.NewReader(""), Stdout: &out, Stderr: &errb, + Program: "yetano-solutions", StoreDir: t.TempDir(), Catalogs: []string{"../engine/testdata/cat"}, + Getenv: func(string) string { return "" }, + }) + if code != ExitInterrupted || ExitInterrupted != 3 || ExitNotFound != 7 { + t.Fatalf("cancelled: exit %d (%s)", code, errb.String()) + } + if r := run(t, t.TempDir(), "solution", "show", "nope"); r.code != 7 { + t.Fatalf("not found: exit %d", r.code) + } +} diff --git a/solutions/cmd/yetano-solutions/main.go b/solutions/cmd/yetano-solutions/main.go index 4b91bb6..7b098d5 100644 --- a/solutions/cmd/yetano-solutions/main.go +++ b/solutions/cmd/yetano-solutions/main.go @@ -10,6 +10,7 @@ import ( "context" "os" "os/signal" + "syscall" "yetano.dev/yetano/core" "yetano.dev/yetano/core/paths" @@ -19,7 +20,7 @@ import ( var version = "dev" func main() { - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() // instances, sessions and presets are user data: core/paths' data // directory (nothing is created until something is saved)