Skip to content

Commit

Permalink
fix(cmd/info): handle "context canceled" errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alacuku committed Aug 31, 2023
1 parent 06cb770 commit 156a652
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/artifact/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package info

import (
"context"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -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)

Check failure on line 95 in cmd/artifact/info/info.go

View workflow job for this annotation

GitHub Actions / Lint golang files

o.Printer undefined (type *artifactInfoOptions has no field or method Printer) (typecheck)
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
}

0 comments on commit 156a652

Please sign in to comment.