From 156a652fe35ebdc985b6a5466418de3fa683ba7a Mon Sep 17 00:00:00 2001 From: Aldo Lacuku Date: Thu, 31 Aug 2023 15:06:21 +0200 Subject: [PATCH] fix(cmd/info): handle "context canceled" errors The command should exit when the context is canceled by a termination signal. In such case the command prints the reason why it exited. Furthermore, the table header is printed to stdout only when data is found for the artifacts. Signed-off-by: Aldo Lacuku --- cmd/artifact/info/info.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/artifact/info/info.go b/cmd/artifact/info/info.go index f1bf2a625..34694cba7 100644 --- a/cmd/artifact/info/info.go +++ b/cmd/artifact/info/info.go @@ -16,6 +16,7 @@ package info import ( "context" + "errors" "fmt" "strings" @@ -90,14 +91,22 @@ func (o *artifactInfoOptions) RunArtifactInfo(ctx context.Context, args []string } tags, err := repo.Tags(ctx) - if err != nil { - o.Printer.Warning.Printfln("cannot retrieve tags from %q, %v", ref, err) + if err != nil && !errors.Is(err, context.Canceled) { + o.Printer.Warning.Printfln("cannot retrieve tags from t %q, %v", ref, err) continue + } else if errors.Is(err, context.Canceled) { + // When the context is canceled we exit, since we receive a termination signal. + return err } joinedTags := strings.Join(tags, ", ") data = append(data, []string{ref, joinedTags}) } - return o.Printer.PrintTable(output.ArtifactInfo, data) + // Print the table header + data only if there is data. + if len(data) > 0 { + return o.Common.Printer.PrintTable(output.ArtifactInfo, data) + } + + return nil }