Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
Harden code against potential nil panics
Browse files Browse the repository at this point in the history
Detected using go.uber.org/nilaway/cmd/nilaway
  • Loading branch information
arnested committed Nov 25, 2023
1 parent c180a92 commit 01f52e5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion post.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *Client) do(ctx context.Context, form url.Values) ([]byte, error) {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

resp, err := c.httpClient().Do(req)
if err != nil {
if (err != nil) || (resp == nil) {
return nil, fmt.Errorf("failed to contact API: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestUpdateOK(t *testing.T) {
_, err := client.Update(ctx, records)
if err != nil {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
if errors.As(err, &netErr) && (netErr != nil) && netErr.Timeout() {
t.Errorf("Timeoutsss: %s", netErr)
} else {
t.Errorf("Successful post should return OK but failed with error: %s", err)
Expand Down

0 comments on commit 01f52e5

Please sign in to comment.