-
-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked how stack traces are rendered
- Loading branch information
Showing
7 changed files
with
217 additions
and
317 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
122 changes: 20 additions & 102 deletions
122
src/Exceptionless.Web/ClientApp/src/lib/components/events/SimpleStackTrace.svelte
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,112 +1,30 @@ | ||
<script lang="ts"> | ||
import type { SimpleErrorInfo } from '$lib/models/client-data'; | ||
export let error: SimpleErrorInfo | undefined; | ||
import { onMount } from 'svelte'; | ||
import { getErrors } from '$lib/helpers/persistent-event'; | ||
import DOMPurify from 'dompurify'; | ||
let textStackTrace: string; | ||
let stackTrace: string; | ||
function buildStackFrames(errors: SimpleErrorInfo[], includeHTML: boolean) { | ||
let frames = ''; | ||
errors.forEach((error, index) => { | ||
const stackTrace = error.stack_trace; | ||
if (stackTrace) { | ||
if (includeHTML) { | ||
frames += `<div class="pl-[10px]">${escapeHTML(stackTrace.replace(' ', ''))}`; | ||
if (index < errors.length - 1) { | ||
frames += '<div>--- End of inner error stack trace ---</div>'; | ||
} | ||
frames += '</div>'; | ||
} else { | ||
frames += stackTrace.replace(' ', ''); | ||
if (index < errors.length - 1) { | ||
frames += '--- End of inner error stack trace ---'; | ||
} | ||
} | ||
} | ||
}); | ||
return frames; | ||
} | ||
import StackTraceHeader from './StackTraceHeader.svelte'; | ||
function buildStackTrace(errors: SimpleErrorInfo[], includeHTML: boolean) { | ||
return ( | ||
buildStackTraceHeader(errors, includeHTML) + | ||
buildStackFrames(errors.reverse(), includeHTML) | ||
); | ||
} | ||
function buildStackTraceHeader(errors: SimpleErrorInfo[], includeHTML: boolean) { | ||
let header = ''; | ||
errors.forEach((error, index) => { | ||
if (includeHTML) { | ||
header += '<span class="block">'; | ||
} | ||
if (index > 0) { | ||
header += ' ---> '; | ||
} | ||
const hasType = !!error.type; | ||
if (hasType) { | ||
if (includeHTML) { | ||
header += `<span class="font-bold">${escapeHTML(error.type)}</span>: `; | ||
} else { | ||
header += `${error.type}: `; | ||
} | ||
} | ||
if (error.message) { | ||
if (includeHTML) { | ||
header += escapeHTML(error.message); | ||
} else { | ||
header += error.message; | ||
} | ||
} | ||
if (hasType) { | ||
if (includeHTML) { | ||
header += '</span>'; | ||
} else { | ||
header += '\r\n'; | ||
} | ||
} | ||
}); | ||
return header; | ||
} | ||
function escapeHTML(input?: string) { | ||
if (!input) { | ||
return input; | ||
} | ||
export let error: SimpleErrorInfo | undefined; | ||
return DOMPurify.sanitize( | ||
input | ||
.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
); | ||
function cleanStackTrace(stackTrace: string) { | ||
return stackTrace.replace(' ', ''); | ||
} | ||
onMount(() => { | ||
const errors = getErrors(error); | ||
stackTrace = buildStackTrace(errors, true); | ||
textStackTrace = buildStackTrace(errors, false); | ||
console.log({ stackTrace, textStackTrace }); | ||
}); | ||
const errors = getErrors(error); | ||
</script> | ||
|
||
<pre | ||
class="max-h-[500px] overflow-y-scroll overflow-x-scroll break-normal resize-y whitespace-pre tab-size-2"><code | ||
>{@html stackTrace}</code | ||
></pre> | ||
class="max-h-[500px] overflow-y-scroll overflow-x-scroll break-normal resize-y whitespace-pre tab-size-2"> | ||
<code> | ||
<StackTraceHeader {errors}></StackTraceHeader> | ||
{#each errors.reverse() as error, index} | ||
{#if error.stack_trace} | ||
<div class="pl-[10px]">{cleanStackTrace( | ||
error.stack_trace | ||
)}</div> | ||
{#if index < errors.length - 1} | ||
<div>--- End of inner error stack trace ---</div> | ||
{/if} | ||
{/if} | ||
{/each} | ||
</code> | ||
</pre> |
Oops, something went wrong.