Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8a219a84b |
No files matched your search
+13
-6
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user