diff --git a/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx b/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx index 9d4a76510aa8..fd6eec17cb40 100644 --- a/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx +++ b/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx @@ -1,6 +1,6 @@ import {Box, ErrorBoundary, Text} from '@sanity/ui' import {type ComponentProps, useCallback, useId, useState} from 'react' -import {useTranslation} from 'sanity' +import {useSource, useTranslation} from 'sanity' import {Dialog} from '../../../ui-components' import {structureLocaleNamespace} from '../../i18n' @@ -17,6 +17,18 @@ function ConfirmDeleteDialogContainer(props: ConfirmDeleteDialogProps) { const id = useId() const [error, setError] = useState(null) const handleRetry = useCallback(() => setError(null), []) + const {onStudioError} = useSource() + + const handleCatchError = useCallback( + ({error: caughtError, info: caughtInfo}: {error: Error; info: React.ErrorInfo}) => { + setError({error: caughtError, info: caughtInfo}) + + if (onStudioError) { + onStudioError(caughtError, caughtInfo) + } + }, + [onStudioError], + ) return error ? ( ) : ( - + ) diff --git a/packages/sanity/src/structure/components/structureTool/StructureTitle.tsx b/packages/sanity/src/structure/components/structureTool/StructureTitle.tsx index 426f684e4484..3bd2b940702e 100644 --- a/packages/sanity/src/structure/components/structureTool/StructureTitle.tsx +++ b/packages/sanity/src/structure/components/structureTool/StructureTitle.tsx @@ -46,6 +46,7 @@ const DocumentTitle = (props: {documentId: string; documentType: string}) => { document.title = newTitle }, [documentTitle, settled, newTitle]) + throw new Error('This is an error from the structure tool') return null } diff --git a/packages/sanity/src/structure/components/structureTool/StructureToolBoundary.tsx b/packages/sanity/src/structure/components/structureTool/StructureToolBoundary.tsx index a9fbb7a3063f..a3aeb047a91b 100644 --- a/packages/sanity/src/structure/components/structureTool/StructureToolBoundary.tsx +++ b/packages/sanity/src/structure/components/structureTool/StructureToolBoundary.tsx @@ -1,5 +1,5 @@ import {ErrorBoundary} from '@sanity/ui' -import {useEffect, useState} from 'react' +import {useCallback, useEffect, useState} from 'react' import {SourceProvider, type Tool, useWorkspace} from 'sanity' import {setActivePanes} from '../../getIntentState' @@ -25,6 +25,7 @@ export function StructureToolBoundary({tool: {options}}: StructureToolBoundaryPr }, []) const [{error}, setError] = useState<{error: unknown}>({error: null}) + // this re-throws if the error it catches is not a PaneResolutionError if (error) return diff --git a/packages/sanity/src/structure/panes/document/inspectors/validation/ValidationInspector.tsx b/packages/sanity/src/structure/panes/document/inspectors/validation/ValidationInspector.tsx index b3d7c94e5827..419ad16cbec3 100644 --- a/packages/sanity/src/structure/panes/document/inspectors/validation/ValidationInspector.tsx +++ b/packages/sanity/src/structure/panes/document/inspectors/validation/ValidationInspector.tsx @@ -13,7 +13,7 @@ import { } from '@sanity/types' import {Box, Card, type CardTone, ErrorBoundary, Flex, Stack, Text} from '@sanity/ui' import {createElement, type ErrorInfo, Fragment, useCallback, useMemo, useState} from 'react' -import {type DocumentInspectorProps, useTranslation} from 'sanity' +import {type DocumentInspectorProps, useSource, useTranslation} from 'sanity' import {DocumentInspectorHeader} from '../../documentInspector' import {useDocumentPane} from '../../useDocumentPane' @@ -44,6 +44,7 @@ export function ValidationInspector(props: DocumentInspectorProps) { [onFocus, onPathOpen], ) + throw new Error('This is an error from the validation inspector') return (