-
Notifications
You must be signed in to change notification settings - Fork 417
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
fix: Don't call c.Error(...)
inside echotrace middlewares
#2609
Changes from all commits
d3735fb
ea63b88
230fae8
74931da
7fc87fe
d74b236
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 |
---|---|---|
|
@@ -151,9 +151,13 @@ func TestError(t *testing.T) { | |
mt := mocktracer.Start() | ||
defer mt.Stop() | ||
var called, traced bool | ||
handlerCalled := 0 | ||
|
||
// setup | ||
router := echo.New() | ||
router.HTTPErrorHandler = func(err error, c echo.Context) { | ||
handlerCalled++ | ||
} | ||
router.Use(Middleware(WithServiceName("foobar"))) | ||
wantErr := errors.New("oh no") | ||
|
||
|
@@ -163,7 +167,6 @@ func TestError(t *testing.T) { | |
called = true | ||
|
||
err := wantErr | ||
c.Error(err) | ||
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. @rarguelloF I've updated the test to ensure that the error handler is called once, and I've removed the
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. The fact that this change has removed this call and not broken anything in the rest of test should hopefully further highlight the fact that the expected behavior is already happening without this call, and explicitly calling it is causing as a second, unnecessary call. |
||
return err | ||
}) | ||
r := httptest.NewRequest("GET", "/err", nil) | ||
|
@@ -173,6 +176,7 @@ func TestError(t *testing.T) { | |
// verify the errors and status are correct | ||
assert.True(called) | ||
assert.True(traced) | ||
assert.Equal(1, handlerCalled) | ||
|
||
spans := mt.FinishedSpans() | ||
require.Len(t, spans, 1) | ||
|
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.
I think we should add some test to verify this behavior and ensure we don't introduce a regression in the future.
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.
@rarguelloF Actually, if somebody was relying in the existing behaviour, they probably won't feel a difference. The existing behaviour blocked middlewares running before our own to manipulate the response, as
c.Error
already commited it to the client.I think it's safe to go ahead as it is right now.