Skip to content

Commit 8e88f97

Browse files
committed
chore: improve error messages #130
1 parent b06c795 commit 8e88f97

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/transport/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package transport
1616

1717
import (
1818
"context"
19+
"errors"
1920
"fmt"
2021
"net"
2122
"os"
@@ -26,6 +27,8 @@ import (
2627
"github.com/buraksezer/olric/internal/protocol"
2728
)
2829

30+
var ErrConnPoolTimeout = errors.New("timeout exceeded")
31+
2932
// Client is the client implementation for the internal TCP server.
3033
// It maintains a connection pool and manages request-response cycle.
3134
type Client struct {
@@ -129,7 +132,12 @@ func (c *Client) conn(addr string) (net.Conn, error) {
129132

130133
conn, err := p.Get(ctx)
131134
if err != nil {
132-
return nil, err
135+
// Reformat the error here. DeadlineExceeded error is too
136+
// cryptic for users.
137+
if err == context.DeadlineExceeded {
138+
err = ErrConnPoolTimeout
139+
}
140+
return nil, fmt.Errorf("failed to acquire a TCP connection from the pool for: %s %w", addr, err)
133141
}
134142

135143
if c.config.HasTimeout() {

0 commit comments

Comments
 (0)