diff --git a/bun.lockb b/bun.lockb index c0145f0..16c0c62 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 056139a..b5fb7a4 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "masto": "^6.8.0", "nanostores": "^0.9.5", "solid-js": "^1.8.18", - "solid-styled": "^0.11.1" + "solid-styled": "^0.11.1", + "stacktrace-js": "^2.0.2" }, "packageManager": "bun@1.1.21" } diff --git a/src/App.tsx b/src/App.tsx index 55e9971..1522795 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -53,11 +53,13 @@ const App: Component = () => { ); }); +const UnexpectedError = lazy(() => import("./UnexpectedError.js")) + return ( { console.error(err); - return <>; + return ; }} > diff --git a/src/UnexpectedError.tsx b/src/UnexpectedError.tsx new file mode 100644 index 0000000..38e3c70 --- /dev/null +++ b/src/UnexpectedError.tsx @@ -0,0 +1,40 @@ +import { Button } from '@suid/material'; +import {Component, createResource} from 'solid-js' +import { css } from 'solid-styled'; + +const UnexpectedError: Component<{error?: any}> = (props) => { + + const [errorMsg] = createResource(() => props.error, async (err) => { + if (err instanceof Error) { + const mod = await import('stacktrace-js') + const stacktrace = await mod.fromError(err) + const strackMsg = stacktrace.map(entry => `${entry.functionName ?? ""}@${entry.fileName}:(${entry.lineNumber}:${entry.columnNumber})`).join('\n') + return `${err.name}: ${err.message}\n${strackMsg}` + } + + return err.toString() + }) + + css` + main { + padding: calc(var(--safe-area-inset-top) + 20px) calc(var(--safe-area-inset-right) + 20px) calc(var(--safe-area-inset-bottom) + 20px) calc(var(--safe-area-inset-left) + 20px); + } + ` + + return
+

Oh, it is our fault.

+

There is an unexpected error in our app, and it's not your fault.

+

You can reload to see if this guy is gone. If you meet this guy repeatly, please report to us.

+
+ +
+
+ {errorMsg.loading ? 'Generating ' : " "}Technical Infomation (Bring to us if you report the problem) +
+        {errorMsg()}
+      
+
+
+} + +export default UnexpectedError;