Skip to content

Commit

Permalink
Handle unhandled errors in tools/
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSnowden committed Dec 22, 2022
1 parent 2171a17 commit 9b7cdb1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
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

0 comments on commit 9b7cdb1

Please sign in to comment.