-
Notifications
You must be signed in to change notification settings - Fork 4.7k
client: wrap context errors returned by DialContext #8835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,7 +323,7 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn * | |
| case err == nil || !cc.dopts.returnLastError: | ||
| 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()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Should |
||
| } | ||
| default: | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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