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..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 (