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 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Opus 5.5 committed 2026-12-01 13:21:10 +01:00
1 parent 4fb9bf9a5a
commit c8a219a84b
3 files changed
+34 -7

No files matched your search

+13 -6
View File
@@ -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):
+19
View File
@@ -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)
}
}