From b52980d2eda387743d26d4c3f2a802027c496832 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 16 Jul 2026 15:36:09 +1000 Subject: [PATCH] [UI] Display error information in boundary (#12403) * Display error information in boundary * Fix SecurityContext --- src/frontend/lib/components/Boundary.tsx | 51 ++++++++++++------- .../AccountSettings/SecurityContent.tsx | 7 ++- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/frontend/lib/components/Boundary.tsx b/src/frontend/lib/components/Boundary.tsx index 2d1bca4436..045eec46d8 100644 --- a/src/frontend/lib/components/Boundary.tsx +++ b/src/frontend/lib/components/Boundary.tsx @@ -1,27 +1,35 @@ import { t } from '@lingui/core/macro'; import { Alert, Stack, Text } from '@mantine/core'; import { ErrorBoundary, type FallbackRender } from '@sentry/react'; -import { IconExclamationCircle } from '@tabler/icons-react'; -import { type ReactNode, useCallback } from 'react'; +import { IconExclamationCircle, IconInfoCircle } from '@tabler/icons-react'; +import { type ReactNode, useCallback, useState } from 'react'; export function DefaultFallback({ - title -}: Readonly<{ title: string }>): ReactNode { + title, + error +}: Readonly<{ title: string; error: string | null }>): ReactNode { return ( - } - title={`INVE-E17: ${t`Error rendering component`}: ${title}`} - > - - - {t`An error occurred while rendering this component. Refer to the console for more information.`} - - - {t`Try reloading the page, or contact your administrator if the problem persists.`} - - - + <> + } + title={`INVE-E17: ${t`Error rendering component`}: ${title}`} + > + + + {t`An error occurred while rendering this component.`} + + + {t`Try reloading the page, or contact your administrator if the problem persists.`} + + + + {error && ( + } title={t`Error Details`}> + {error} + + )} + ); } @@ -34,17 +42,22 @@ export function Boundary({ label: string; fallback?: React.ReactElement | FallbackRender; }>): ReactNode { + const [errorMessage, setErrorMessage] = useState(null); + const onError = useCallback( (error: unknown, componentStack: string | undefined, eventId: string) => { console.error(`ERR: Error rendering component: ${label}`); console.error(error); + setErrorMessage(error instanceof Error ? error.message : String(error)); }, [] ); return ( } + fallback={ + fallback ?? + } onError={onError} > {children} diff --git a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx index 3d7e13c4a2..ba208eb739 100644 --- a/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx +++ b/src/frontend/src/pages/Index/Settings/AccountSettings/SecurityContent.tsx @@ -45,9 +45,12 @@ export function SecurityContent() { const user = useUserState(); + const [errorMessage, setErrorMessage] = useState(null); + const onError = useCallback( (error: unknown, componentStack: string | undefined, eventId: string) => { console.error(`ERR: Error rendering component: ${error}`); + setErrorMessage(error instanceof Error ? error.message : String(error)); }, [] ); @@ -95,7 +98,9 @@ export function SecurityContent() { } + fallback={ + + } onError={onError} >