Skip to content

Commit

Permalink
Merge #72352
Browse files Browse the repository at this point in the history
72352: server,cli: fix improperly wrapped errors r=knz a=rafiss

refs #42510

I'm working on a linter that detects errors that are not wrapped
correctly, and it discovered these.

Release note: None

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Nov 3, 2021
2 parents 05d3662 + b12219b commit 2154996
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/base/store_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func NewSizeSpec(
size.Percent, err = strconv.ParseFloat(factorValue, 64)
size.Percent *= percentFactor
if err != nil {
return SizeSpec{}, errors.Newf("could not parse %s size (%s) %s", field, value, err)
return SizeSpec{}, errors.Wrapf(err, "could not parse %s size (%s)", field, value)
}
if percentRange != nil {
if (percentRange.min != nil && size.Percent < *percentRange.min) ||
Expand All @@ -112,7 +112,7 @@ func NewSizeSpec(
var err error
size.InBytes, err = humanizeutil.ParseBytes(value)
if err != nil {
return SizeSpec{}, errors.Newf("could not parse %s size (%s) %s", field, value, err)
return SizeSpec{}, errors.Wrapf(err, "could not parse %s size (%s)", field, value)
}
if bytesRange != nil {
if bytesRange.min != nil && size.InBytes < *bytesRange.min {
Expand Down
2 changes: 1 addition & 1 deletion pkg/base/store_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ target_file_size=2097152`
{"path=/mnt/hda1,size=.009999", "store size (.009999) must be between 1.000000% and 100.000000%", StoreSpec{}},
// errors
{"path=/mnt/hda1,size=0", "store size (0) must be larger than 640 MiB", StoreSpec{}},
{"path=/mnt/hda1,size=abc", "could not parse store size (abc) strconv.ParseFloat: parsing \"\": invalid syntax", StoreSpec{}},
{"path=/mnt/hda1,size=abc", "could not parse store size (abc): strconv.ParseFloat: parsing \"\": invalid syntax", StoreSpec{}},
{"path=/mnt/hda1,size=", "no value specified for size", StoreSpec{}},
{"size=20GiB,path=/mnt/hda1,size=20GiB", "size field was used twice in store definition", StoreSpec{}},
{"size=123TB", "no path specified", StoreSpec{}},
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/clisqlclient/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestConnRecover(t *testing.T) {
// this however.
testutils.SucceedsSoon(t, func() error {
if sqlRows, err := conn.Query(`SELECT 1`, nil); !errors.Is(err, driver.ErrBadConn) {
return errors.Newf("expected ErrBadConn, got %v", err)
return errors.NewAssertionErrorWithWrappedErrf(err, "expected ErrBadConn")
} else if err == nil {
if closeErr := sqlRows.Close(); closeErr != nil {
t.Fatal(closeErr)
Expand All @@ -89,7 +89,7 @@ func TestConnRecover(t *testing.T) {
// Ditto from Query().
testutils.SucceedsSoon(t, func() error {
if err := conn.Exec(`SELECT 1`, nil); !errors.Is(err, driver.ErrBadConn) {
return errors.Newf("expected ErrBadConn, got %v", err)
return errors.NewAssertionErrorWithWrappedErrf(err, "expected ErrBadConn")
}
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/clisqlshell/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ func (c *cliState) execSyscmd(command string) (string, error) {
cmd.Stderr = c.iCtx.stderr

if err := cmd.Run(); err != nil {
return "", fmt.Errorf("error in external command: %s", err)
return "", errors.Wrap(err, "error in external command")
}

return out.String(), nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func doTestDrain(tt *testing.T) {
if grpcutil.IsClosedConnection(err) {
return nil
}
return errors.Newf("server not yet refusing RPC, got %v", err)
return errors.NewAssertionErrorWithWrappedErrf(err, "server not yet refusing RPC")
})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func (n *Node) start(
// gossip can bootstrap using the most recently persisted set of
// node addresses.
if err := n.storeCfg.Gossip.SetStorage(n.stores); err != nil {
return fmt.Errorf("failed to initialize the gossip interface: %s", err)
return errors.Wrap(err, "failed to initialize the gossip interface")
}

// Initialize remaining stores/engines, if any.
Expand Down

0 comments on commit 2154996

Please sign in to comment.