From 1b923412649c263048d8752de5fb445239d346ad Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Thu, 27 Aug 2026 15:07:20 -0400 Subject: [PATCH] Fail step context list when there are no contexts step context list printed nothing and exited 0 when STEPPATH has no contexts, which is indistinguishable from a successful listing of an empty set and gives a caller no way to tell the two apart. step context current already errors with "no context selected" and exits 1 in the equivalent situation, so match it. Fixes #879 Signed-off-by: Arpit Jain --- command/context/list.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/command/context/list.go b/command/context/list.go index 2d0e585e..afa9a615 100644 --- a/command/context/list.go +++ b/command/context/list.go @@ -3,6 +3,7 @@ package context import ( "fmt" + "github.com/pkg/errors" "github.com/urfave/cli" "github.com/smallstep/cli-utils/command" @@ -37,12 +38,20 @@ ssh.beta func listAction(*cli.Context) error { cs := step.Contexts() + contexts := cs.ListAlphabetical() + if len(contexts) == 0 { + // Printing nothing and exiting 0 is indistinguishable from a STEPPATH + // that has contexts but none of them listable, so say so and fail the + // way `step context current` does when there is nothing selected. + return errors.New("no contexts present") + } + cur := cs.GetCurrent() if cur != nil { fmt.Printf("▶ %s\n", cur.Name) } - for _, v := range cs.ListAlphabetical() { + for _, v := range contexts { if cur != nil && v.Name == cur.Name { continue }