mirror of
https://github.com/misode/misode.github.io.git
synced 2026-05-01 21:23:12 +00:00
Add more info to the generated crash report
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
|
import { getCurrentUrl } from 'preact-router'
|
||||||
import { useEffect, useMemo, useState } from 'preact/hooks'
|
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'
|
import { Octicon } from './index.js'
|
||||||
|
|
||||||
type ErrorPanelProps = {
|
type ErrorPanelProps = {
|
||||||
@@ -6,9 +11,13 @@ type ErrorPanelProps = {
|
|||||||
onDismiss?: () => unknown,
|
onDismiss?: () => unknown,
|
||||||
}
|
}
|
||||||
export function ErrorPanel({ error, onDismiss }: ErrorPanelProps) {
|
export function ErrorPanel({ error, onDismiss }: ErrorPanelProps) {
|
||||||
|
const { version } = useVersion()
|
||||||
const [stackVisible, setStackVisible] = useState(false)
|
const [stackVisible, setStackVisible] = useState(false)
|
||||||
const [stack, setStack] = useState<string | undefined>(undefined)
|
const [stack, setStack] = useState<string | undefined>(undefined)
|
||||||
|
|
||||||
|
const gen = getGenerator(getCurrentUrl())
|
||||||
|
const source = gen ? Store.getBackup(gen.id) : undefined
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
const stack = error.stack!.split('\n').map(line => {
|
const stack = error.stack!.split('\n').map(line => {
|
||||||
@@ -28,16 +37,23 @@ export function ErrorPanel({ error, onDismiss }: ErrorPanelProps) {
|
|||||||
|
|
||||||
const url = useMemo(() => {
|
const url = useMemo(() => {
|
||||||
let url ='https://github.com/misode/misode.github.io/issues/new'
|
let url ='https://github.com/misode/misode.github.io/issues/new'
|
||||||
if (error instanceof Error) {
|
url += `?title=${encodeURIComponent(error instanceof Error ? `${error.name}: ${error.message}` : error.toString())}`
|
||||||
url += `?title=${encodeURIComponent(`${error.name}: ${error.message}`)}`
|
let body = ''
|
||||||
if (stack) {
|
body += `## Crash report\n * Page url: \`${location.href}\`\n`
|
||||||
url += `&body=${encodeURIComponent(`\`\`\`\n${error.name}: ${error.message}\n${stack}\n\`\`\`\n`)}`
|
if (gen) {
|
||||||
|
body += ` * Generator ID: \`${gen.id}\`\n`
|
||||||
}
|
}
|
||||||
} else {
|
body += ` * Current version: \`${version}\`\n`
|
||||||
url += `?title=${encodeURIComponent(error.toString())}`
|
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<details>\n<pre>\n${JSON.stringify(source, null, 2)}\n</pre>\n</details>\n`
|
||||||
|
}
|
||||||
|
url += `&body=${encodeURIComponent(body)}`
|
||||||
return url
|
return url
|
||||||
}, [error, stack])
|
}, [error, version, stack, source, gen?.id])
|
||||||
|
|
||||||
return <div class="error">
|
return <div class="error">
|
||||||
{onDismiss && <div class="error-dismiss" onClick={onDismiss}>{Octicon.x}</div>}
|
{onDismiss && <div class="error-dismiss" onClick={onDismiss}>{Octicon.x}</div>}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ type Version = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
declare var __LATEST_VERSION__: string
|
declare var __LATEST_VERSION__: string
|
||||||
const latestVersion = __LATEST_VERSION__ ?? ''
|
export const latestVersion = __LATEST_VERSION__ ?? ''
|
||||||
const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta'
|
const mcmetaUrl = 'https://raw.githubusercontent.com/misode/mcmeta'
|
||||||
const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball'
|
const mcmetaTarballUrl = 'https://github.com/misode/mcmeta/tarball'
|
||||||
const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'
|
const changesUrl = 'https://raw.githubusercontent.com/misode/technical-changes'
|
||||||
|
|||||||
Reference in New Issue
Block a user