/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React, {type ComponentProps, type ReactNode} from 'react'; import Translate from '@docusaurus/Translate'; import {getErrorCausalChain} from '@docusaurus/utils-common'; import type {Props as ErrorProps} from '@theme/Error'; import styles from './errorBoundaryUtils.module.css'; export function ErrorBoundaryTryAgainButton( props: ComponentProps<'button'>, ): ReactNode { return ( ); } // A very simple reusable ErrorBoundary fallback component export function ErrorBoundaryErrorMessageFallback({ error, tryAgain, }: ErrorProps): ReactNode { return (

{error.message}

); } export function ErrorBoundaryError({error}: {error: Error}): ReactNode { const causalChain = getErrorCausalChain(error); const fullMessage = causalChain.map((e) => e.message).join('\n\nCause:\n'); return

{fullMessage}

; } /** * This component is useful to wrap a low-level error into a more meaningful * error with extra context, using the ES error-cause feature. * * new Error("extra context message",{cause: error})} * > * * */ export class ErrorCauseBoundary extends React.Component< { children: React.ReactNode; onError: (error: Error, errorInfo: React.ErrorInfo) => Error; }, unknown > { override componentDidCatch(error: Error, errorInfo: React.ErrorInfo): never { throw this.props.onError(error, errorInfo); } override render(): React.ReactNode { return this.props.children; } }