-
Notifications
You must be signed in to change notification settings - Fork 37
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
APIError.GRPCStatus returns "OK" for all http errors. #254
Comments
@ribrdb The apierror.APIError type returned by
Do you think this description could be improved to make the situation clearer? |
How are we supposed to tell which one to use? |
Does the application code not have the context of whether the transport is gRPC or HTTP? |
I don't know how we would. Some google apis are returning errors wrapped with APIError. Is our code supposed to know whether that api is using grpc or rest? |
Client libraries (not APIs) return errors wrapped with APIError. If you can list some of the client libraries you are using, I may be able to answer whether that client is using grpc or rest.
As you know, |
Well the way we checked before is to see if the error has a GRPCStatus method. But your error objects have a GRPCStatus method that returns something that method should never return. You are returning a nil status object. A nil status object means "no error ocurred" not "this wasn't a grpc error". |
Thanks, I think your usage makes sense and is clear now. I'll see what can be done. |
I'm going to change the title of this issue to indicate that apierror.APIError should support querying whether it wraps a gRPC |
I don't think adding a way to query solves the problem. Why can't case isHTTPErr:
a.httpErr = herr
a.details = parseHTTPDetails(herr)
a.status = status.New(codes.UNKNOWN, herr.Message) Or have |
The current implementation of |
Hey @ribrdb, @quartzmo will go ahead with your suggested fix here. Would mind sharing which API clients you are using? I just want to learn more, that is all. Obviously there is a gap in how we anticipated this being used by end users and how it actually is. Specifically, when you said the following:
My first thought was "Yes, this should be known to the user". Now I realize that we were wrong in making that assumption, and this is definitely not the fault of the user. Some more thinking/context you may (or may not) care about: With the clients in |
Here's some background context on our side. When we found the apierror package we tried wrapping the http errors from Google Classroom so we could get access to the error details for debugging. But this caused many things to break because the status changed from UNKNOWN to OK. It also seems like classroom is returning grpc statuses because we see the status code names in the error messages. It would be nice if we could access that directly because the grpc ones seem more specific, but the googleapi.Error only exposes the http status code, even if the response contains a grpc status. |
@ribrdb You're using google.golang.org/api/classroom/v1? |
Yes. I just want to mention what has been the most confusing thing for us. When we use the classroom api, we see errors that look a lot like grpc errors. For example, they say "permission denied" instead of "forbidden". But then we can't handle them using the concise |
* return Unknown status when googleapi.Error because gRPC treats nil as OK closes: googleapis#254
We've been hit by this too, this becomes nasty when we make use of error unwrapping. Our code looks like this:
|
I think we might need to look into conditionally supporting the That said, users will always need to adjust their error handling based on when they are using HTTP or gRPC as a transport. |
@codyoss wdyt? |
I think this is better now with grpc 1.55: https://github.com/grpc/grpc-go/releases/tag/v1.55.0 "status: status.Code and status.FromError handle wrapped errors" |
When using apierror.FromError with an http error, the
status
field does not get populated, so the GRPCStatus() method returns nil. It seems like this is intended to mean "no status is available". However, the status package treats nil as "OK":https://github.com/grpc/grpc-go/blob/dba26e15a07f43875ccf806a2dd6cbcbc1c12eab/internal/status/status.go#L72
The status package also says that no non-nil error should have status of "OK".
To properly fulfil this contract, it seems that the APIError.status should never be nil. I would expect it to at least return UNKNOWN, but it looks like the json error may also include a
status
field with a grpc status code, and some of the http status code seem to map directly to grpc codes (e.g. 404, 429, 503):https://cloud.google.com/apis/design/errors#handling_errors
The text was updated successfully, but these errors were encountered: