-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
141 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script setup lang="ts"> | ||
import type { StackFrame } from 'error-stack-parser-es' | ||
defineProps<{ | ||
stacktrace: StackFrame[] | ||
}>() | ||
const config = useServerConfig() | ||
function urlToFilepath(url: string) { | ||
try { | ||
let pathname = new URL(url).pathname | ||
if (pathname.startsWith('/_nuxt/')) | ||
pathname = pathname.slice(6) | ||
if (pathname.startsWith('/@id/virtual:nuxt:')) | ||
return `#build/${pathname.split('/.nuxt/')[1]}`.replace(/\.m?js$/, '') | ||
if (pathname.includes('/@fs/')) | ||
return `/${pathname.split('/@fs/')[1]}` | ||
return (config.value?.rootDir || '') + pathname | ||
} | ||
catch (e) { | ||
return url | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div mt2 grid="~ cols-[max-content_1fr] gap-x-4" font-mono> | ||
<template v-for="item, idx of stacktrace" :key="idx"> | ||
<div text-right> | ||
{{ item.functionName || `(anonymous)` }} | ||
</div> | ||
<div ws-nowrap> | ||
<FilepathItem | ||
v-if="item.fileName" | ||
:filepath="`${urlToFilepath(item.fileName)}:${item.lineNumber}:${item.columnNumber}`" | ||
subpath | ||
/> | ||
</div> | ||
</template> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<script setup lang="ts"> | ||
import { parse as parseStrackTrace } from 'error-stack-parser-es' | ||
definePageMeta({ | ||
icon: 'i-carbon-warning-alt-filled text-red', | ||
title: 'Error', | ||
category: 'app', | ||
show() { | ||
const client = useClient() | ||
return () => client.value?.nuxt?.payload?.error | ||
}, | ||
}) | ||
const client = useClient() | ||
const error = computed(() => { | ||
const err = client.value?.nuxt?.payload?.error as { | ||
url?: string | ||
statusCode?: number | ||
statusMessage?: string | ||
message?: string | ||
description?: string | ||
data?: any | ||
} & Error | ||
if (err) { | ||
console.error('[Nuxt DevTools] Error in payload:') | ||
console.error(err) | ||
console.error({ ...err }) | ||
} | ||
return err | ||
}) | ||
const stacks = computed(() => { | ||
if (!error.value?.stack) | ||
return [] | ||
try { | ||
// Nuxt server returns a HTML rendered stacktrace, workaround by removing all HTML tags | ||
if (error.value.stack.startsWith('<pre>')) { | ||
return parseStrackTrace({ | ||
stack: error.value.stack.replace(/<.*?>/g, ''), | ||
} as any) | ||
} | ||
return parseStrackTrace(error.value) | ||
} | ||
catch (e) { | ||
console.error(e) | ||
return [] | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div p6> | ||
<div v-if="error"> | ||
<NTip n="red" icon="i-carbon-warning-alt-filled" mb5> | ||
Error occurred in this page | ||
</NTip> | ||
<div text-6xl> | ||
{{ error.statusCode || 'Client Error' }} | ||
</div> | ||
<div v-if="error.statusMessage" op75> | ||
{{ error.statusMessage }} | ||
</div> | ||
<div my4 text-xl text-red> | ||
{{ error.message || error.description || 'Unknown error' }} | ||
</div> | ||
<div v-if="stacks.length || error.stack" of-auto rounded bg-active p2> | ||
<div px1 op50> | ||
Stacktrace | ||
</div> | ||
<StacktraceList v-if="stacks.length" px2 :stacktrace="stacks" /> | ||
<pre v-else v-text="error.stack" /> | ||
</div> | ||
</div> | ||
<div v-else op50> | ||
No error | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script setup lang="ts"> | ||
throw new Error('This is an error thrown from error.vue') | ||
</script> | ||
|
||
<template> | ||
<div> | ||
Error | ||
</div> | ||
</template> |