Skip to content

client: wrap context errors returned by DialContext#8835

Open
easwars wants to merge 1 commit intogrpc:masterfrom
easwars:wrapped_errors_from_dial
Open

client: wrap context errors returned by DialContext#8835
easwars wants to merge 1 commit intogrpc:masterfrom
easwars:wrapped_errors_from_dial

Conversation

@easwars
Copy link
Contributor

@easwars easwars commented Jan 14, 2026

Fixes #4822

RELEASE NOTES:

  • client: DialContext now wraps context errors, allowing users to use errors.Is to check for timeouts or cancellations

@easwars easwars requested a review from dfawley January 14, 2026 07:44
@easwars easwars added the Type: Feature New features or improvements in behavior label Jan 14, 2026
@easwars easwars added this to the 1.79 Release milestone Jan 14, 2026
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.23%. Comparing base (572fdca) to head (6600380).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8835      +/-   ##
==========================================
- Coverage   83.31%   83.23%   -0.08%     
==========================================
  Files         414      414              
  Lines       32753    32753              
==========================================
- Hits        27288    27263      -25     
- Misses       4064     4083      +19     
- Partials     1401     1407       +6     
Files with missing lines Coverage Δ
clientconn.go 90.33% <100.00%> (-0.48%) ⬇️

... and 26 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

conn, err = nil, ctx.Err()
default:
conn, err = nil, fmt.Errorf("%v: %v", ctx.Err(), err)
conn, err = nil, fmt.Errorf("%v: %w", err, ctx.Err())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are returning wrapped errors, the inner error has become part of our public API. We must avoid breaking users who rely on errors.Is in the future. I think we should ensure all possible wrapped errors are explicitly documented in the godoc.

See go/go-style/best-practices#documentation-conventions-errors

conn, err = nil, ctx.Err()
default:
conn, err = nil, fmt.Errorf("%v: %v", ctx.Err(), err)
conn, err = nil, fmt.Errorf("%v: %w", err, ctx.Err())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reverse the order of the text output?

Also can we switch this outer select to:

ctxErr := ctx.Err()
if ctxErr == nil {
  return // use err as-is
}
switch { ..... }

But then that raises a question for me: if we aren't doing returnLastError, but FailOnNonTempDialError is set, what does that even mean? In this case, it looks like we are returning the connection error, unless there is also a context error, in which case we return it instead?

Should FailOnNonTempDialError imply both WithBlock and WithReturnConnectionError? I guess it shouldn't imply WithBlock but it seems like it should set returnLastError otherwise it's unpredictable.

@mbissa mbissa modified the milestones: 1.80 Release, 1.81 Release Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client: use error wrapping for WithReturnConnectionError

5 participants