Skip to content
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

Use structured error types in frontend RPC service #6570

Merged
merged 3 commits into from
May 16, 2024

Conversation

bduffany
Copy link
Member

@bduffany bduffany commented May 14, 2024

(This is all behind the streaming_http_enabled flag, which is only enabled in dev currently.)

This PR is preparing for making server-streaming RPCs retryable on the client. Ideally we'd always retry these, otherwise when the apps roll out, the live-streaming would suddenly stop.

We currently throw a somewhat haphazard mixture of string and TypeError from the RPC service methods when a fetch fails. This PR updates things to be more structured, so that we can more easily distinguish between gRPC status errors, other HTTP errors (with status code + body, but missing gRPC error message), or generic network errors (e.g. can't reach the app, app restarted, etc.).

Related issues: N/A

@bduffany bduffany changed the title Use structured error types in RPC service Use structured error types in frontend RPC service May 14, 2024
@bduffany bduffany force-pushed the rpc-structured-errors branch 2 times, most recently from 7d2cdab to c5bb892 Compare May 14, 2024 16:51
@bduffany bduffany marked this pull request as ready for review May 14, 2024 16:53
@bduffany bduffany force-pushed the rpc-structured-errors branch 6 times, most recently from 5632e7b to a7071c3 Compare May 15, 2024 15:19
} catch (e) {
message = `unknown (failed to read response body: ${e})`;
if (structuredErrors) {
// If we failed to read the response body then ignore the status code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about this precedence--I guess we still have the network tab to tell the difference, I just figure if a 500 error yielded an unparseable response then saying "500" is more useful than "failed to read".

Copy link
Member Author

@bduffany bduffany May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that this approach would play more nicely with retry middleware (on the frontend) if we return a generic network error here. That way if we return an error status but fail to read the response body, the client can at least retry for a chance to get a more informative error message that could maybe help them fix the error. I guess if the client got permanently disconnected though, they will be stuck with the "failed to read" error, but I think that's not too much worse than 500: <failed to read body>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah alright, i'm sold


/**
* High-level error class representing any error from the BuildBuddy server,
* either GRPC or HTTP.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class hierarchy is a little weird here based on the documentation--do you actually intend to flip the code on its head at some point (HTTPStatusError extends BBError) or more cleanly compose things so that HTTPStatusError/FetchError etc are held by BBError?

Copy link
Member Author

@bduffany bduffany May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thanks for pointing this out - I think what I would like to do is:

  • Get rid of BuildBuddyError entirely - it's sort of poorly defined
  • In the places where we're doing stuff like catch (e) { error_service.handleError(BuildBuddyError.parse(e)); } we would just pass e instead of trying to parse the error. It's kind of ugly that we "parse" errors at all and I would rather have the errors be nicely structured at a lower level to begin with.
  • The error_service could then do nicer stuff depending on the type of error that it's rendering, rather than receiving a generic BuildBuddyError which is more "watered down". e.g. for FetchError we could show a nice "network broken" icon or something like that (if we really wanted to, haha)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works, how about plopping something in the comment here about what the plan is?

@bduffany bduffany requested a review from jdhollen May 15, 2024 20:57
@bduffany
Copy link
Member Author

Gah I accidentally merged #6578 into this PR. Fixing up the commits now...

} catch (e) {
message = `unknown (failed to read response body: ${e})`;
if (structuredErrors) {
// If we failed to read the response body then ignore the status code
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah alright, i'm sold


/**
* High-level error class representing any error from the BuildBuddy server,
* either GRPC or HTTP.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works, how about plopping something in the comment here about what the plan is?

@bduffany
Copy link
Member Author

Sure, that works, how about plopping something in the comment here about what the plan is?

Done

@bduffany bduffany merged commit e39ca68 into master May 16, 2024
13 of 18 checks passed
@bduffany bduffany deleted the rpc-structured-errors branch May 16, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants