Skip to content

Commit

Permalink
chore: improve error messages #130
Browse files Browse the repository at this point in the history
  • Loading branch information
buraksezer committed Dec 20, 2021
1 parent b06c795 commit 8e88f97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/transport/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package transport

import (
"context"
"errors"
"fmt"
"net"
"os"
Expand All @@ -26,6 +27,8 @@ import (
"github.com/buraksezer/olric/internal/protocol"
)

var ErrConnPoolTimeout = errors.New("timeout exceeded")

// Client is the client implementation for the internal TCP server.
// It maintains a connection pool and manages request-response cycle.
type Client struct {
Expand Down Expand Up @@ -129,7 +132,12 @@ func (c *Client) conn(addr string) (net.Conn, error) {

conn, err := p.Get(ctx)
if err != nil {
return nil, err
// Reformat the error here. DeadlineExceeded error is too
// cryptic for users.
if err == context.DeadlineExceeded {
err = ErrConnPoolTimeout
}
return nil, fmt.Errorf("failed to acquire a TCP connection from the pool for: %s %w", addr, err)
}

if c.config.HasTimeout() {
Expand Down

0 comments on commit 8e88f97

Please sign in to comment.