Skip to content

Conversation

@selfcontained
Copy link
Contributor

@selfcontained selfcontained commented Mar 29, 2023

Description

Adding a new <QueryErrorBoundary> to handle expected api errors that queries may throw. These will currently only come from the 2 queries we've enabled the useErrorBoundary option on.

  • getLoggedInUser() - code
  • listTeams() - code

When these queries throw, they're caught first by the <QueryErrorBoundary>, which will handle any errors where code is one of NOT_AUTHENTICATED or SETUP_REQUIRED (we can add more in the future as we need). If it's not one of those errors, we re-throw it, and let it get caught by our default error boundary, now renamed to <ReloadPageErrorBoundary> for clarity. This one continues to report the error, and render a view to ask the user to reload the page. This should only be reached by unanticipated errors.

A nice side effect is it cleans up a bunch of the rendering in the main <App/> component.

Related Issue(s)

Fixes WEB-70

How to test

Preview Env: https://bmh-top-le869d9d8254.preview.gitpod-dev.com/workspaces

  • On the preview environment, test logging in and out.

Other tests to exercise the error boundary are harder to test, as you have to simulate errors in different spots.

// simulate a not authenticated error throw { code: 401, message: "simulated error" }; // simulate a needs setup error throw { code: 410, message: "simulated error" }; // Simulate a server error throw { code: 500, message: "simulated error" };

Release Notes

NONE 

Documentation

Build Options:

  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish Options
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer Options
  • with-dedicated-emulation
  • with-ws-manager-mk2
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated

Preview Environment Options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh
@werft-gitpod-dev-com
Copy link

started the job as gitpod-build-bmh-top-level-error-boundary.1 because the annotations in the pull request description changed
(with .werft/ from main)

<QueryErrorResetBoundary>
{({ reset }) => (
// Passing reset to onReset so any queries know to retry after boundary is reset
<ErrorBoundary FallbackComponent={ExpectedQueryErrorsFallback} onReset={reset}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

passing reset into here will tell react-query to reset any queries once the boundary has been reset.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, nice! Wondered before how this happens/if it's the default/hard-wired behavior 💡 🧡

}
}

return <Login onLoggedIn={resetErrorBoundary} />;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's important to reset the error boundary once we've gotten into a state that shouldn't produce it anymore. This tells react (and react query) to reset state, and try the render again.

</Subheading>
<div>
<button onClick={resetErrorBoundary}>Reload</button>
<button onClick={handleReset}>Reload</button>
Copy link
Contributor Author

@selfcontained selfcontained Mar 30, 2023

Choose a reason for hiding this comment

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

I this case we don't actually want to ask React to try and re-render, we want to just have the user reload the page. We may want to have a route-level error boundary that does attempt a re-render on reset though as a future improvement.

@selfcontained selfcontained marked this pull request as ready for review March 30, 2023 17:35
@selfcontained selfcontained requested a review from a team March 30, 2023 17:35
@selfcontained selfcontained requested a review from gtsiolis as a code owner March 30, 2023 17:35
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label Mar 30, 2023
} finally {
trackLocation(!!user);
}
const user = await getGitpodService().server.getLoggedInUser();
Copy link
Member

Choose a reason for hiding this comment

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

Wow. This looking really clean now! 🎉

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I think this in combination with the QueryErrorBoundary, could serve as one example on how to use react-query.
WDYT @selfcontained?


// Wrap the App in an ErrorBoundary to catch User/Org loading errors
// This will also catch any errors that happen to bubble all the way up to the top
const AppWithErrorBoundary: FC = () => {
Copy link
Member

Choose a reason for hiding this comment

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

This is superfluous now, right? Or am I missing sth? (asking to understand)

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

The code LGTM, tested and works. ✔️

I have some minor clarification questions.

/hold But I think it's worth discussion if we want to keep main clean during the offsite, and have a "merge freeze" (see slack)

@roboquat roboquat merged commit 8ddad67 into main Mar 31, 2023
@roboquat roboquat deleted the bmh/top-level-error-boundary branch March 31, 2023 08:28
@geropl
Copy link
Member

geropl commented Mar 31, 2023

/hold But I think it's worth discussion if we want to keep main clean during the offsite, and have a "merge freeze" (see slack)

exhaling roboquat... 😞

AlexTugarev added a commit that referenced this pull request Mar 31, 2023
roboquat pushed a commit that referenced this pull request Mar 31, 2023
@atduarte
Copy link
Contributor

atduarte commented Apr 4, 2023

/reviewpad robin prompt can you find any issues with this implementation?

@reviewpad
Copy link

reviewpad bot commented Apr 4, 2023

After carefully reviewing the provided git patches, I found some potential issues and improvements:

  1. In components/dashboard/src/App.tsx, the previously existing check for redirecting to the www site has been removed. This change means that if the user isn't logged in and doesn't have a Gitpod cookie, they will not be redirected to the www site as before. If this redirection is still a requirement, you may want to reconsider this change.

  2. In the newly created components/dashboard/src/components/error-boundaries/QueryErrorBoundary.tsx, I noticed that it's not handling unexpected errors. If the caughtError doesn't match any expected error code, it simply re-throws the error. However, there's no other ErrorBoundary wrapping this QueryErrorBoundary that can catch this re-thrown error. So, if an unexpected error occurs, it could lead to an uncaught error and result in an unhandled error state.

To fix this, you could either:

a. Wrap the QueryErrorBoundary with another ErrorBoundary (e.g., ReloadPageErrorBoundary) to catch unexpected errors that are re-thrown.
b. Adjust the QueryErrorBoundary Fallback Component to handle both expected and unexpected errors, similar to the previously used TopLevelErrorFallback.

Other than these issues, the overall implementation seems fine. The code is well-structured and modular, and the patches are organized well into meaningful segments.

Furisto pushed a commit that referenced this pull request Apr 6, 2023
* handle api errors in error boundary * handling resetting the error boundary * splitting out error boundary types
Furisto pushed a commit that referenced this pull request Apr 7, 2023
* handle api errors in error boundary * handling resetting the error boundary * splitting out error boundary types
selfcontained added a commit that referenced this pull request Apr 11, 2023
roboquat pushed a commit that referenced this pull request Apr 12, 2023
* Revert "Revert "handle api errors in error boundary (#17086)" (#17111)" This reverts commit 97ab740. * don't retry current user query * adjusting comment
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deployed: webapp Meta team change is running in production deployed Change is completely running in production do-not-merge/hold release-note-none size/L team: webapp Issue belongs to the WebApp team

5 participants