From 1c8895f23f81a06d6f203c36992fbcd8a9f426e1 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sun, 9 Jul 2023 13:54:53 +0800 Subject: [PATCH] feat: improve error log message (#3112) --- .../affine/affine-error-eoundary.tsx | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/affine/affine-error-eoundary.tsx b/apps/web/src/components/affine/affine-error-eoundary.tsx index 7416c87e24..68dc7b4033 100644 --- a/apps/web/src/components/affine/affine-error-eoundary.tsx +++ b/apps/web/src/components/affine/affine-error-eoundary.tsx @@ -4,8 +4,16 @@ import type { WorkspaceNotFoundError, } from '@affine/env/constant'; import { PageNotFoundError } from '@affine/env/constant'; +import { + rootCurrentPageIdAtom, + rootCurrentWorkspaceIdAtom, + rootWorkspacesMetadataAtom, +} from '@affine/workspace/atom'; +import { rootStore } from '@toeverything/plugin-infra/manager'; +import { useAtomValue } from 'jotai/react'; +import { Provider } from 'jotai/react'; import type { NextRouter } from 'next/router'; -import type { ErrorInfo, ReactNode } from 'react'; +import type { ErrorInfo, ReactElement, ReactNode } from 'react'; import type React from 'react'; import { Component } from 'react'; @@ -24,6 +32,33 @@ interface AffineErrorBoundaryState { error: AffineError | null; } +export const DumpInfo = (props: Pick) => { + const router = props.router; + const metadata = useAtomValue(rootWorkspacesMetadataAtom); + const currentWorkspaceId = useAtomValue(rootCurrentWorkspaceIdAtom); + const currentPageId = useAtomValue(rootCurrentPageIdAtom); + const path = router.asPath; + const query = router.query; + return ( + <> +
+ Please copy the following information and send it to the developer. +
+
+
path: {path}
+
query: {JSON.stringify(query)}
+
currentWorkspaceId: {currentWorkspaceId}
+
currentPageId: {currentPageId}
+
metadata: {JSON.stringify(metadata)}
+
+ + ); +}; + export class AffineErrorBoundary extends Component< AffineErrorBoundaryProps, AffineErrorBoundaryState @@ -44,9 +79,10 @@ export class AffineErrorBoundary extends Component< public override render(): ReactNode { if (this.state.error) { + let errorDetail: ReactElement | null = null; const error = this.state.error; if (error instanceof PageNotFoundError) { - return ( + errorDetail = ( <>

Sorry.. there was an error

<> @@ -76,11 +112,20 @@ export class AffineErrorBoundary extends Component< ); + } else { + errorDetail = ( + <> +

Sorry.. there was an error

+ {error.message ?? error.toString()} + + ); } return ( <> -

Sorry.. there was an error

- {error.message ?? error.toString()} + {errorDetail} + + + ); }