Skip to content

Commit bea96b4

Browse files
committed
added email body to help link
1 parent a5f1aa9 commit bea96b4

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

site/src/components/RuntimeErrorState/RuntimeErrorReport.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ export const reducer = (model: ReportState, msg: ReportMessage): ReportState =>
4949
}
5050
}
5151

52+
export const createFormattedStackTrace = (error: Error, mappedStack: string[] | null): string[] => {
53+
return [
54+
"======================= STACK TRACE ========================",
55+
"",
56+
error.message,
57+
...(mappedStack ? mappedStack : []),
58+
"",
59+
"============================================================",
60+
]
61+
}
62+
5263
/**
5364
* A code block component that contains the error stack resulting from an error boundary trigger
5465
*/
@@ -59,16 +70,8 @@ export const RuntimeErrorReport = ({ error, mappedStack }: ReportState): React.R
5970
return <CodeBlock lines={[Language.reportLoading]} className={styles.codeBlock} />
6071
}
6172

62-
const codeBlock = [
63-
"======================= STACK TRACE ========================",
64-
"",
65-
error.message,
66-
...mappedStack,
67-
"",
68-
"============================================================",
69-
]
70-
71-
return <CodeBlock lines={codeBlock} className={styles.codeBlock} ctas={createCtas(codeBlock)} />
73+
const formattedStackTrace = createFormattedStackTrace(error, mappedStack)
74+
return <CodeBlock lines={formattedStackTrace} className={styles.codeBlock} ctas={createCtas(formattedStackTrace)} />
7275
}
7376

7477
const useStyles = makeStyles(() => ({

site/src/components/RuntimeErrorState/RuntimeErrorState.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ describe("RuntimeErrorState", () => {
3838
it("should have an email link", () => {
3939
// Then
4040
const emailLink = screen.getByText(RuntimeErrorStateLanguage.link)
41-
expect(emailLink.closest("a")).toHaveAttribute("href", "mailto:support@coder.com")
41+
expect(emailLink.closest("a")).toHaveAttribute("href", expect.stringContaining("mailto:support@coder.com"))
4242
})
4343
})

site/src/components/RuntimeErrorState/RuntimeErrorState.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { mapStackTrace } from "sourcemapped-stacktrace"
77
import { Margins } from "../Margins/Margins"
88
import { Section } from "../Section/Section"
99
import { Typography } from "../Typography/Typography"
10-
import { reducer, RuntimeErrorReport, stackTraceAvailable, stackTraceUnavailable } from "./RuntimeErrorReport"
10+
import {
11+
createFormattedStackTrace,
12+
reducer,
13+
RuntimeErrorReport,
14+
stackTraceAvailable,
15+
stackTraceUnavailable,
16+
} from "./RuntimeErrorReport"
1117

1218
export const Language = {
1319
title: "Coder encountered an error",
@@ -35,12 +41,17 @@ const ErrorStateTitle = () => {
3541
/**
3642
* A description for our error boundary UI
3743
*/
38-
const ErrorStateDescription = () => {
44+
const ErrorStateDescription = ({ emailBody }: { emailBody?: string }) => {
3945
const styles = useStyles()
4046
return (
4147
<Typography variant="body2" color="textSecondary">
4248
{Language.body}&nbsp;
43-
<Link href="mailto:support@coder.com" className={styles.link}>
49+
<Link
50+
href={`mailto:support@coder.com?subject=Error Report from Coder&body=${
51+
emailBody && emailBody.replace(/\r\n|\r|\n/g, "%0D%0A") // preserving line breaks
52+
}`}
53+
className={styles.link}
54+
>
4455
{Language.link}
4556
</Link>
4657
</Typography>
@@ -65,7 +76,15 @@ export const RuntimeErrorState: React.FC<RuntimeErrorStateProps> = ({ error }) =
6576
return (
6677
<Box display="flex" flexDirection="column">
6778
<Margins>
68-
<Section className={styles.reportContainer} title={<ErrorStateTitle />} description={<ErrorStateDescription />}>
79+
<Section
80+
className={styles.reportContainer}
81+
title={<ErrorStateTitle />}
82+
description={
83+
<ErrorStateDescription
84+
emailBody={createFormattedStackTrace(reportState.error, reportState.mappedStack).join("\r\n")}
85+
/>
86+
}
87+
>
6988
<RuntimeErrorReport error={reportState.error} mappedStack={reportState.mappedStack} />
7089
</Section>
7190
</Margins>

0 commit comments

Comments
 (0)