Skip to content

Commit

Permalink
report broken pipe with right code, not PIT-000
Browse files Browse the repository at this point in the history
  • Loading branch information
henrod committed May 17, 2019
1 parent 01d8f56 commit 2ba242a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func NewAgent(
func (a *Agent) send(m pendingMessage) (err error) {
defer func() {
if e := recover(); e != nil {
err = constants.ErrBrokenPipe
err = errors.NewError(constants.ErrBrokenPipe, errors.ErrClientClosedRequest)
}
}()
a.reportChannelSize()
Expand All @@ -145,7 +145,7 @@ func (a *Agent) send(m pendingMessage) (err error) {
// Push implementation for session.NetworkEntity interface
func (a *Agent) Push(route string, v interface{}) error {
if a.GetStatus() == constants.StatusClosed {
return constants.ErrBrokenPipe
return errors.NewError(constants.ErrBrokenPipe, errors.ErrClientClosedRequest)
}

switch d := v.(type) {
Expand All @@ -167,7 +167,7 @@ func (a *Agent) ResponseMID(ctx context.Context, mid uint, v interface{}, isErro
err = isError[0]
}
if a.GetStatus() == constants.StatusClosed {
err := constants.ErrBrokenPipe
err := errors.NewError(constants.ErrBrokenPipe, errors.ErrClientClosedRequest)
tracing.FinishSpan(ctx, err)
metrics.ReportTimingFromCtx(ctx, a.metricsReporters, handlerType, err)
return err
Expand Down
11 changes: 6 additions & 5 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestAgentSend(t *testing.T) {
err error
}{
{"success", nil},
{"failure", constants.ErrBrokenPipe},
{"failure", e.NewError(constants.ErrBrokenPipe, e.ErrClientClosedRequest)},
}

for _, table := range tables {
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestAgentPushFailsIfClosedAgent(t *testing.T) {
assert.NotNil(t, ag)
ag.state = constants.StatusClosed
err := ag.Push("", nil)
assert.Equal(t, constants.ErrBrokenPipe, err)
assert.Equal(t, e.NewError(constants.ErrBrokenPipe, e.ErrClientClosedRequest), err)
}

func TestAgentPush(t *testing.T) {
Expand All @@ -206,7 +206,7 @@ func TestAgentPush(t *testing.T) {
}{
{"success_raw", []byte("ok"), nil},
{"success_struct", &someStruct{A: "ok"}, nil},
{"failure", []byte("ok"), constants.ErrBrokenPipe},
{"failure", []byte("ok"), e.NewError(constants.ErrBrokenPipe, e.ErrClientClosedRequest)},
}

for _, table := range tables {
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestAgentResponseMIDFailsIfClosedAgent(t *testing.T) {
mockMetricsReporters[0].(*metricsmocks.MockReporter).EXPECT().ReportSummary(metrics.ResponseTime, gomock.Any(), gomock.Any())
ctx := getCtxWithRequestKeys()
err := ag.ResponseMID(ctx, 1, nil)
assert.Equal(t, constants.ErrBrokenPipe, err)
assert.Equal(t, e.NewError(constants.ErrBrokenPipe, e.ErrClientClosedRequest), err)
}

func TestAgentResponseMID(t *testing.T) {
Expand All @@ -309,7 +309,8 @@ func TestAgentResponseMID(t *testing.T) {
{"success_raw_msg_err", uint(rand.Int()), []byte("ok"), true, nil},
{"success_struct", uint(rand.Int()), &someStruct{A: "ok"}, false, nil},
{"failure_empty_mid", 0, []byte("ok"), false, constants.ErrSessionOnNotify},
{"failure_send", uint(rand.Int()), []byte("ok"), false, constants.ErrBrokenPipe},
{"failure_send", uint(rand.Int()), []byte("ok"), false,
e.NewError(constants.ErrBrokenPipe, e.ErrClientClosedRequest)},
}

for _, table := range tables {
Expand Down
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const ErrNotFoundCode = "PIT-404"
// ErrBadRequestCode is a string code representing a bad request related error
const ErrBadRequestCode = "PIT-400"

// ErrClientClosedRequest is a string code representing the client closed request error
const ErrClientClosedRequest = "PIT-499"

// Error is an error with a code, message and metadata
type Error struct {
Code string
Expand Down

0 comments on commit 2ba242a

Please sign in to comment.