Skip to content

Commit

Permalink
Merge pull request #38 from thiagokokada/improve-error
Browse files Browse the repository at this point in the history
request: improve error handling in RawRequest() defer
  • Loading branch information
thiagokokada authored Sep 10, 2024
2 parents ae6789f + 7ff55fe commit 44fa8dc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,15 @@ func (c *RequestClient) RawRequest(request RawRequest) (response RawResponse, er

// Connect to the request socket
conn, err := net.DialUnix("unix", nil, c.conn)
if err != nil {
return nil, fmt.Errorf("error while connecting to socket: %w", err)
}
defer func() {
if e := conn.Close(); e != nil {
err = fmt.Errorf("error while closing socket: %w", e)
err = errors.Join(err, fmt.Errorf("error while closing socket: %w", e))
}
}()

if err != nil {
return nil, fmt.Errorf("error while connecting to socket: %w", err)
}

// Send the request to the socket
if len(request) > bufSize {
return nil, fmt.Errorf(
Expand Down

0 comments on commit 44fa8dc

Please sign in to comment.