Skip to content

Commit cffc1a6

Browse files
committed
always log request details when cancelled
1 parent 06fda91 commit cffc1a6

4 files changed

Lines changed: 45 additions & 48 deletions

File tree

errpendingcancelled.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

errrequestcancelled.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package jaws
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/linkdata/jaws/lib/assets"
7+
)
8+
9+
// ErrRequestCancelled indicates a Request was cancelled. Use Unwrap() to see the underlying cause.
10+
var ErrRequestCancelled errRequestCancelled
11+
12+
type errRequestCancelled struct {
13+
JawsKey uint64
14+
Cause error
15+
Initial string
16+
}
17+
18+
func (e errRequestCancelled) Error() string {
19+
return fmt.Sprintf("Request<%s>:%s %v", assets.JawsKeyString(e.JawsKey), e.Initial, e.Cause)
20+
}
21+
22+
func (e errRequestCancelled) Is(target error) (yes bool) {
23+
return target == ErrRequestCancelled
24+
}
25+
26+
func (e errRequestCancelled) Unwrap() error {
27+
return e.Cause
28+
}
29+
30+
func newErrRequestCancelledLocked(rq *Request, cause error) (err error) {
31+
var initial string
32+
if rq.initial != nil {
33+
initial = fmt.Sprintf(" %s %q:", rq.initial.Method, rq.initial.RequestURI)
34+
}
35+
return errRequestCancelled{
36+
JawsKey: rq.JawsKey,
37+
Cause: cause,
38+
Initial: initial,
39+
}
40+
}

request.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,7 @@ func (rq *Request) maintenance(now time.Time, requestTimeout time.Duration) bool
339339

340340
func (rq *Request) cancelLocked(err error) {
341341
if rq.JawsKey != 0 && rq.ctx.Err() == nil {
342-
if !rq.running.Load() {
343-
err = newErrPendingCancelledLocked(rq, err)
344-
}
345-
rq.cancelFn(rq.Jaws.Log(err))
342+
rq.cancelFn(rq.Jaws.Log(newErrRequestCancelledLocked(rq, err)))
346343
}
347344
}
348345

request_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,13 +1036,13 @@ func TestRequest_CustomErrors(t *testing.T) {
10361036
rq := newTestRequest(t)
10371037
defer rq.Close()
10381038
cause := newErrNoWebSocketRequest(rq.Request)
1039-
err := newErrPendingCancelledLocked(rq.Request, cause)
1040-
th.True(errors.Is(err, ErrPendingCancelled))
1039+
err := newErrRequestCancelledLocked(rq.Request, cause)
1040+
th.True(errors.Is(err, ErrRequestCancelled))
10411041
th.True(errors.Is(err, ErrNoWebSocketRequest))
1042-
th.Equal(errors.Is(cause, ErrPendingCancelled), false)
1042+
th.Equal(errors.Is(cause, ErrRequestCancelled), false)
10431043
var target1 errNoWebSocketRequest
10441044
th.True(errors.As(err, &target1))
1045-
var target2 errPendingCancelled
1045+
var target2 errRequestCancelled
10461046
th.Equal(errors.As(cause, &target2), false)
10471047
}
10481048

0 commit comments

Comments
 (0)