-
Notifications
You must be signed in to change notification settings - Fork 569
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
Do not use grpc/status.FromError() and gogo/status.FromError() #7224
Conversation
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.
Makes sense to me.
Signed-off-by: Marco Pracucci <[email protected]>
3b857e5
to
4ed52da
Compare
Makefile
Outdated
@@ -306,6 +306,10 @@ lint: check-makefiles | |||
# Ensure all errors are report as APIError | |||
faillint -paths "github.com/weaveworks/common/httpgrpc.{Errorf}=github.com/grafana/mimir/pkg/api/error.Newf" ./pkg/frontend/querymiddleware/... | |||
|
|||
# Do not use grpc/status.FromError() because doesn't support wrapped errors. |
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.
This is actually not true:
grpc/status.FromError()
support wrapped errors (it useserrors.As()
internally)gogo/status.FromError()
doesn't support wrapped errors (it doesn't useerrors.As()
internally)
So, I'd suggest to decommission both grpc/status.FromError()
and gogo/status.FromError()
and use grpcutil.ErrorToStatus()
instead.
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 I was completely drunk when I worked on this PR 🤦
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.
@duricanikolic I should have fix it.
Signed-off-by: Marco Pracucci <[email protected]>
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.
LGTM
I have added some non-blocking suggestions.
@@ -78,7 +79,7 @@ func TestNewCircuitBreaker(t *testing.T) { | |||
|
|||
// Failed request that should put the circuit breaker into "open" | |||
err = breaker(context.Background(), "/cortex.Ingester/Push", "", "", &conn, failure) | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Unavailable, code)
@@ -79,7 +78,7 @@ func TestSendQueryStream(t *testing.T) { | |||
// Try to receive the response and assert the error we get is the context.Canceled | |||
// wrapped within a gRPC error. | |||
_, err = stream.Recv() | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Canceled, code)
@@ -6504,7 +6504,7 @@ func TestIngester_PushInstanceLimits(t *testing.T) { | |||
assert.ErrorIs(t, err, testData.expectedErr) | |||
var optional middleware.OptionalLogging | |||
assert.ErrorAs(t, err, &optional) | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Unavailable, code)
@@ -6824,7 +6824,7 @@ func TestIngester_inflightPushRequests(t *testing.T) { | |||
require.ErrorAs(t, err, &optional) | |||
require.False(t, optional.ShouldLog(ctx, time.Duration(0)), "expected not to log via .ShouldLog()") | |||
|
|||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Unavailable, code)
@@ -6931,7 +6931,7 @@ func TestIngester_inflightPushRequestsBytes(t *testing.T) { | |||
require.ErrorAs(t, err, &optional) | |||
require.False(t, optional.ShouldLog(ctx, time.Duration(0)), "expected not to log via .ShouldLog()") | |||
|
|||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Unavailable, code)
@@ -2033,14 +2033,14 @@ func TestBucketStore_Series_CanceledRequest(t *testing.T) { | |||
srv := newStoreGatewayTestServer(t, store) | |||
_, _, _, _, err = srv.Series(ctx, req) | |||
assert.Error(t, err) | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Canceled, code)
assert.True(t, ok) | ||
assert.Equal(t, codes.Canceled, s.Code()) | ||
|
||
req.StreamingChunksBatchSize = 10 | ||
_, _, _, _, err = srv.Series(ctx, req) | ||
assert.Error(t, err) | ||
s, ok = status.FromError(err) | ||
s, ok = grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok = grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Canceled, code)
@@ -2747,7 +2747,7 @@ func TestLabelNames_Cancelled(t *testing.T) { | |||
|
|||
_, err := store.LabelNames(ctx, req) | |||
assert.Error(t, err) | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Canceled, code)
@@ -2774,7 +2774,7 @@ func TestLabelValues_Cancelled(t *testing.T) { | |||
|
|||
_, err := store.LabelValues(ctx, req) | |||
assert.Error(t, err) | |||
s, ok := status.FromError(err) | |||
s, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
s, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, codes.Canceled, code)
@@ -43,7 +43,7 @@ func TestLimiter(t *testing.T) { | |||
} | |||
|
|||
func checkErrorStatusCode(t *testing.T, err error) { | |||
st, ok := status.FromError(err) | |||
st, ok := grpcutil.ErrorToStatus(err) |
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.
[nit]
Another possibility would be:
st, ok := grpcutil.ErrorToStatus(err) | |
code := grpcutil.ErrorToStatusCode(err) |
and then to check
require.Equal(t, uint32(http.StatusUnprocessableEntity), code)
Thanks @duricanikolic for the review. I checked at the nits you've left about using |
What this PR does
In the review of #7213 I've learned from @duricanikolic that:
Since we want support for errors wrapping everywhere, to avoid subtle bugs depending on which status package is imported, I propose to never allow
.FromError()
, replace it withgrpcutil.ErrorToStatus()
and add afaillint
rule to enforce it.Which issue(s) this PR fixes or relates to
N/A
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.