diff --git a/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx b/packages/sanity/src/structure/components/confirmDeleteDialog/index.tsx index 9d4a76510aa8..af90199e9072 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,7 @@ function ConfirmDeleteDialogContainer(props: ConfirmDeleteDialogProps) { const id = useId() const [error, setError] = useState(null) const handleRetry = useCallback(() => setError(null), []) + const {onStudioError} = useSource() return error ? ( { 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..7582d1cf9717 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,11 +25,24 @@ export function StructureToolBoundary({tool: {options}}: StructureToolBoundaryPr }, []) const [{error}, setError] = useState<{error: unknown}>({error: null}) + + const handleCatchError = useCallback( + ({error: caughtError, info: caughtInfo}: {error: Error; info: React.ErrorInfo}) => { + setError({error: caughtError}) + const {onStudioError} = firstSource + + if (onStudioError) { + onStudioError(caughtError, caughtInfo) + } + }, + [firstSource], + ) + // this re-throws if the error it catches is not a PaneResolutionError if (error) return 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 (