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

Display an error message when the service is unreachable #8490

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

khuddite
Copy link
Contributor

@khuddite khuddite commented Nov 13, 2024

Fixes #8487

  1. Summary
    We block the rest of the UI if we fail to fetch client config from the back-end for whatever reason. Therefore, a white screen is displayed without any feedback whenever that happens.
    ClientConfigProvider is the component that blocks UI when the client config has not been loaded.

  2. Solution
    It ended up being more changes than I anticipated but those changes were necessary. I removed ClientConfigProvider to unblock the rest of the UI even if the back-end is unreachable. Used enqueueSnackBar to display an error message when the client config failed to load. Used isClientConfigLoaded in a couple of places to ensure no further requests are made if client config fetch fails.

  3. Recording

CleanShot.2024-11-13.at.17.01.03.mp4

Honestly, I am unsure if it's the best way to tackle the issue, but I'd like to receive feedback on this.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR improves error handling when the backend service is unreachable by removing blocking UI behavior and adding clear error messaging.

  • Removed ClientConfigProvider component to prevent UI blocking when client config fails to load
  • Added error snackbar notification in ClientConfigProviderEffect when backend is unreachable
  • Added isClientConfigLoaded check in UserProviderEffect to prevent unnecessary network requests
  • Modified PageChangeEffect to check client config status before tracking analytics
  • Updated test decorators to reflect new non-blocking architecture

6 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 32 to 33
<ClientConfigProviderEffect />
<ClientConfigProvider>
<ChromeExtensionSidecarEffect />
<ChromeExtensionSidecarProvider>
<UserProviderEffect />
<UserProvider>
<AuthProvider>
<ApolloMetadataClientProvider>
<ObjectMetadataItemsProvider>
<PrefetchDataProvider>
<AppThemeProvider>
<SnackBarProvider>
<DialogManagerScope dialogManagerScopeId="dialog-manager">
<DialogManager>
<StrictMode>
<PromiseRejectionEffect />
<GotoHotkeysEffectsProvider />
<PageTitle title={pageTitle} />
<Outlet />
</StrictMode>
</DialogManager>
</DialogManagerScope>
</SnackBarProvider>
</AppThemeProvider>
</PrefetchDataProvider>
<PageChangeEffect />
</ObjectMetadataItemsProvider>
</ApolloMetadataClientProvider>
</AuthProvider>
</UserProvider>
</ChromeExtensionSidecarProvider>
</ClientConfigProvider>
<ChromeExtensionSidecarEffect />
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: ClientConfigProviderEffect and ChromeExtensionSidecarEffect may try to make API calls before SnackBarProvider is mounted, potentially losing error messages

Comment on lines 50 to 55
if (error !== undefined) {
enqueueSnackBar('Unable to reach backend', {
variant: SnackBarVariant.Error,
});
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: setIsClientConfigLoaded(false) should be called here to ensure the state accurately reflects the failed load

@@ -90,5 +102,7 @@ export const ClientConfigProviderEffect = () => {
setIsAnalyticsEnabled,
]);

console.log('error: ', error, loading);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: remove console.log before merging to production

Comment on lines 71 to +73
<ClientConfigProviderEffect />
<ClientConfigProvider>
<UserProviderEffect />
<UserProvider>
<ApolloMetadataClientMockedProvider>
<ObjectMetadataItemsProvider>
<FullHeightStorybookLayout>
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<IconsProvider>
<PrefetchDataProvider>
<Outlet />
</PrefetchDataProvider>
</IconsProvider>
</SnackBarProviderScope>
</HelmetProvider>
</FullHeightStorybookLayout>
</ObjectMetadataItemsProvider>
</ApolloMetadataClientMockedProvider>
</UserProvider>
</ClientConfigProvider>
<UserProviderEffect />
<UserProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: UserProviderEffect depends on client config being loaded, but now runs regardless of client config status. This could cause cascading errors if client config fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's causing any issues here

@khuddite khuddite marked this pull request as draft November 13, 2024 22:22
@khuddite khuddite marked this pull request as ready for review November 13, 2024 22:37
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR continues the error handling improvements by implementing comprehensive error capture and display mechanisms across the application.

  • Added PromiseRejectionEffect to catch and display unhandled promise rejections via snackbar
  • Moved ClientConfigProviderEffect after SnackBarProvider in provider hierarchy to ensure error messages are displayed
  • Added error handling for ObjectMetadataItemNotFoundError with specific error message
  • Added Sentry integration placeholder in PromiseRejectionEffect for future error tracking

3 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

});
return;
}
if (isDefined(data?.clientConfig)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: consider adding an else clause to handle undefined clientConfig case explicitly

@FelixMalfait
Copy link
Member

Thanks a lot!!!
I'm not sure this is the best solution too. @lucasbordeau what do you think? Should we keep this approach?
One thing that I like is that I feel it could improve performance positively by making this query less render-blocking and starting to display more components sooner.
But on the other hand having the ClientConfigProviderEffect so far down the component stack feels wrong as it's almost meant to be "environment variable for the frontend" so something quite generic that's accessible across the code.
Also the tests broke, not sure if it's easy to fix them @khuddite? Maybe let's wait for confirmation from @lucasbordeau to make sure you don't waste time

@FelixMalfait FelixMalfait self-assigned this Nov 15, 2024
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.

Improve error message when server isn't responding on first page load
2 participants