Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd/info): handle "context canceled" errors #320

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
cache: 'false'

- name: golangci-lint
uses: golangci/golangci-lint-action@08e2f20817b15149a52b5b3ebe7de50aff2ba8c5 # v3.4.0
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
only-new-issues: true
version: v1.52
version: v1.54.2
args: --timeout=900s

gomodtidy:
Expand Down
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)
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.Printer.PrintTable(output.ArtifactInfo, data)
}

return nil
}