mirror of https://github.com/golang/go.git
net/http: build error chains in transport that can be unwrapped
In some places of the HTTP transport errors were constructed that
wrapped other errors without providing the ability to call
`errors.Unwrap` on them to get the underlying error.
These places have been fixed to use `%w` when using `fmt.Errorf`
or to implement `Unwrap() error`.
Fixes #56435
Change-Id: Ieed3359281574485c8d0b18298e25e5f1e14555c
GitHub-Last-Rev: 504efbc507
GitHub-Pull-Request: golang/go#56451
Reviewed-on: https://go-review.googlesource.com/c/go/+/445775
Reviewed-by: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
This commit is contained in:
parent
eca7754148
commit
531ba0c8aa
|
|
@ -2057,7 +2057,7 @@ func (pc *persistConn) mapRoundTripError(req *transportRequest, startBytesWritte
|
|||
if pc.nwrite == startBytesWritten {
|
||||
return nothingWrittenError{err}
|
||||
}
|
||||
return fmt.Errorf("net/http: HTTP/1.x transport connection broken: %v", err)
|
||||
return fmt.Errorf("net/http: HTTP/1.x transport connection broken: %w", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
@ -2264,7 +2264,7 @@ func (pc *persistConn) readLoopPeekFailLocked(peekErr error) {
|
|||
// common case.
|
||||
pc.closeLocked(errServerClosedIdle)
|
||||
} else {
|
||||
pc.closeLocked(fmt.Errorf("readLoopPeekFailLocked: %v", peekErr))
|
||||
pc.closeLocked(fmt.Errorf("readLoopPeekFailLocked: %w", peekErr))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2398,6 +2398,10 @@ type nothingWrittenError struct {
|
|||
error
|
||||
}
|
||||
|
||||
func (nwe nothingWrittenError) Unwrap() error {
|
||||
return nwe.error
|
||||
}
|
||||
|
||||
func (pc *persistConn) writeLoop() {
|
||||
defer close(pc.writeLoopDone)
|
||||
for {
|
||||
|
|
@ -2635,7 +2639,7 @@ func (pc *persistConn) roundTrip(req *transportRequest) (resp *Response, err err
|
|||
req.logf("writeErrCh resv: %T/%#v", err, err)
|
||||
}
|
||||
if err != nil {
|
||||
pc.close(fmt.Errorf("write error: %v", err))
|
||||
pc.close(fmt.Errorf("write error: %w", err))
|
||||
return nil, pc.mapRoundTripError(req, startBytesWritten, err)
|
||||
}
|
||||
if d := pc.t.ResponseHeaderTimeout; d > 0 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue