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

Handle unhandled errors in tools/ #3748

Merged
merged 1 commit into from
Dec 24, 2022
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: 3 additions & 1 deletion tools/cassandra/setupTask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestSetupSchemaTestSuite(t *testing.T) {
}

func (s *SetupSchemaTestSuite) SetupSuite() {
os.Setenv("CASSANDRA_HOST", environment.GetCassandraAddress())
if err := os.Setenv("CASSANDRA_HOST", environment.GetCassandraAddress()); err != nil {
s.Logger.Fatal("Failed to set CASSANDRA_HOST", tag.Error(err))
}
client, err := newTestCQLClient(systemKeyspace)
if err != nil {
s.Logger.Fatal("Error creating CQLClient", tag.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions tools/tdbg/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *utilSuite) TestAcceptStringSliceArgsWithCommas() {
},
},
}
app.Run([]string{"testapp", "dostuff",
s.NoError(app.Run([]string{"testapp", "dostuff",
"--input", `{"field1": 34, "field2": false}`,
"--input", `{"numbers": [4,5,6]}`})
"--input", `{"numbers": [4,5,6]}`}))
}
8 changes: 6 additions & 2 deletions tools/tdbg/dlq_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"

"github.com/urfave/cli/v2"
"go.uber.org/multierr"

"go.temporal.io/server/api/adminservice/v1"
enumsspb "go.temporal.io/server/api/enums/v1"
Expand All @@ -44,7 +45,7 @@ const (
)

// AdminGetDLQMessages gets DLQ metadata
func AdminGetDLQMessages(c *cli.Context) error {
func AdminGetDLQMessages(c *cli.Context) (err error) {
ctx, cancel := newContext(c)
defer cancel()

Expand All @@ -56,7 +57,10 @@ func AdminGetDLQMessages(c *cli.Context) error {
if err != nil {
return err
}
defer outputFile.Close()
defer func() {
// see https://pkg.go.dev/go.uber.org/multierr#hdr-Deferred_Functions
err = multierr.Combine(err, outputFile.Close())
}()

remainingMessageCount := common.EndMessageID
if c.IsSet(FlagMaxMessageCount) {
Expand Down
9 changes: 7 additions & 2 deletions tools/tdbg/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

"github.com/urfave/cli/v2"
"go.temporal.io/api/workflowservice/v1"
"go.uber.org/multierr"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -193,11 +194,15 @@ func fetchCACert(pathOrUrl string) (caPool *x509.CertPool, err error) {
}

if strings.HasPrefix(pathOrUrl, "https://") {
resp, err := netClient.Get(pathOrUrl)
var resp *http.Response
resp, err = netClient.Get(pathOrUrl)
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() {
// see https://pkg.go.dev/go.uber.org/multierr#hdr-Deferred_Functions
err = multierr.Combine(err, resp.Body.Close())
}()
caBytes, err = io.ReadAll(resp.Body)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion tools/tdbg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func paginate[V any](c *cli.Context, paginationFn collection.PaginationFn[V], pa
pageItems = append(pageItems, item)
if len(pageItems) == pageSize || !iter.HasNext() {
if isTableView {
printTable(pageItems)
if err := printTable(pageItems); err != nil {
return err
}
} else {
prettyPrintJSONObject(pageItems)
}
Expand Down