From cd4ef6640a2c752f2e09d30ad16db57cf10330e5 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 23 Nov 2022 08:52:22 +0100 Subject: [PATCH] Add more info to the generated crash report --- src/app/components/ErrorPanel.tsx | 32 +++++++++++++++++++++++-------- src/app/services/DataFetcher.ts | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/app/components/ErrorPanel.tsx b/src/app/components/ErrorPanel.tsx index 75e0172a..c8e6c60b 100644 --- a/src/app/components/ErrorPanel.tsx +++ b/src/app/components/ErrorPanel.tsx @@ -1,4 +1,9 @@ +import { getCurrentUrl } from 'preact-router' import { useEffect, useMemo, useState } from 'preact/hooks' +import { useVersion } from '../contexts/Version.jsx' +import { latestVersion } from '../services/DataFetcher.js' +import { Store } from '../Store.js' +import { getGenerator } from '../Utils.js' import { Octicon } from './index.js' type ErrorPanelProps = { @@ -6,9 +11,13 @@ type ErrorPanelProps = { onDismiss?: () => unknown, } export function ErrorPanel({ error, onDismiss }: ErrorPanelProps) { + const { version } = useVersion() const [stackVisible, setStackVisible] = useState(false) const [stack, setStack] = useState(undefined) + const gen = getGenerator(getCurrentUrl()) + const source = gen ? Store.getBackup(gen.id) : undefined + useEffect(() => { if (error instanceof Error) { const stack = error.stack!.split('\n').map(line => { @@ -28,16 +37,23 @@ export function ErrorPanel({ error, onDismiss }: ErrorPanelProps) { const url = useMemo(() => { let url ='https://github.com/misode/misode.github.io/issues/new' - if (error instanceof Error) { - url += `?title=${encodeURIComponent(`${error.name}: ${error.message}`)}` - if (stack) { - url += `&body=${encodeURIComponent(`\`\`\`\n${error.name}: ${error.message}\n${stack}\n\`\`\`\n`)}` - } - } else { - url += `?title=${encodeURIComponent(error.toString())}` + url += `?title=${encodeURIComponent(error instanceof Error ? `${error.name}: ${error.message}` : error.toString())}` + let body = '' + body += `## Crash report\n * Page url: \`${location.href}\`\n` + if (gen) { + body += ` * Generator ID: \`${gen.id}\`\n` } + body += ` * Current version: \`${version}\`\n` + body += ` * Latest version: \`${latestVersion}\`\n` + if (error instanceof Error && stack) { + body += `\n### Stack trace\n\`\`\`\n${error.name}: ${error.message}\n${stack}\n\`\`\`\n` + } + if (source) { + body += `\n### Generator JSON\n
\n
\n${JSON.stringify(source, null, 2)}\n
\n
\n` + } + url += `&body=${encodeURIComponent(body)}` return url - }, [error, stack]) + }, [error, version, stack, source, gen?.id]) return
{onDismiss &&
{Octicon.x}
} diff --git a/src/app/services/DataFetcher.ts b/src/app/services/DataFetcher.ts index 4f4e04f9..2c3a1a9d 100644 --- a/src/app/services/DataFetcher.ts +++ b/src/app/services/DataFetcher.ts @@ -14,7 +14,7 @@ type Version = { } declare var __LATEST_VERSION__: string -const latestVersion = __LATEST_VERSION__ ?? '' +export const latestVersion = __LATEST_VERSION__ ?? '' const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta' const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball' const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'