aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/sort.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/sort.go')
-rw-r--r--cmd/krino/sort.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/cmd/krino/sort.go b/cmd/krino/sort.go
index 4d5f509..637587d 100644
--- a/cmd/krino/sort.go
+++ b/cmd/krino/sort.go
@@ -134,7 +134,7 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
// of polling forever.
l, err := lock.Acquire(ctx, e.Config.LockFile(d.Name), !g.yes)
if err != nil {
- if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
+ if interrupted(err) {
// Interrupted while waiting for the lock: an interrupt, not
// a failure - the ctx.Err() check at the end of this
// function already turns this into exit 130, and nothing
@@ -258,21 +258,16 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
}
res, aerr := e.Apply(ctx, toApply, approved, j, run)
if aerr != nil {
- if errors.Is(aerr, context.Canceled) || errors.Is(aerr, context.DeadlineExceeded) {
- // Interrupted mid-apply (fix round 2026-09-12/item 2):
- // treated exactly like the cancelled lock wait above -
- // not a failure ("context canceled" is a Go-ism, not
- // something to show a user who just pressed Ctrl-C),
- // and no further directory is even attempted. The
- // ctx.Err() check at the end of this function already
- // turns this into exit 130.
- return true
+ // Interrupted mid-apply (fix round 2026-09-12/item 2):
+ // treated exactly like the cancelled lock wait above - not
+ // a failure ("context canceled" is a Go-ism, not something
+ // to show a user who just pressed Ctrl-C). The ctx.Err()
+ // check at the end of this function turns it into exit 130.
+ if !interrupted(aerr) {
+ fmt.Fprintf(stderr, "krino: %s: %v\n", d.Name, aerr)
+ exit = 1
}
- fmt.Fprintf(stderr, "krino: %s: %v\n", d.Name, aerr)
- exit = 1
- // [w] stops krino whether or not its apply succeeded (review
- // cli F3): no later directory is planned or asked about.
- return action == 'w'
+ return stopAfterApply(action, aerr)
}
fmt.Fprintln(stdout, withNotReviewed(outcome(p, res.Applied, res.Failed, res.Declined), notReviewed))
// Ruling 1: only an actual step failure makes the run exit 1
@@ -280,7 +275,7 @@ func cmdSort(g *globals, names []string, stdout, stderr io.Writer) int {
if res.Failed > 0 {
exit = 1
}
- return action == 'w'
+ return stopAfterApply(action, nil)
}()
if quit {
@@ -583,3 +578,16 @@ func padCell(s string, w int) string {
}
return s + strings.Repeat(" ", w-n)
}
+
+// interrupted reports whether err is the context being cancelled (Ctrl-C,
+// SIGTERM, SIGHUP) rather than a failure.
+func interrupted(err error) bool {
+ return errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)
+}
+
+// stopAfterApply reports whether krino stops once a directory has been
+// applied: an interrupt stops it, and so does [w], whether or not its apply
+// succeeded (review cli F3) - no later directory is planned or asked about.
+func stopAfterApply(action rune, err error) bool {
+ return interrupted(err) || action == 'w'
+}