Skip to content

Commit c056c0a

Browse files
feat: attach eventId to error page (#7364)
1 parent 587123e commit c056c0a

3 files changed

Lines changed: 68 additions & 7 deletions

File tree

apps/cowswap-frontend/src/legacy/components/ErrorBoundary/ChunkLoadError.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import styled from 'styled-components/macro'
1010
import { ThemedText } from 'theme'
1111

1212
import { AutoColumn } from 'legacy/components/Column'
13+
import CopyHelper from 'legacy/components/Copy'
1314

1415
// eslint-disable-next-line import/no-internal-modules -- Direct import to avoid circular dependency (barrel re-exports App which imports ErrorBoundary)
1516
import { Title } from 'modules/application/pure/Page'
@@ -36,6 +37,7 @@ function preloadNoConnectionImg(): void {
3637
.then((img) => {
3738
cowNoConnectionIMGCache = img
3839
})
40+
.catch(() => {})
3941
}
4042

4143
preloadNoConnectionImg()
@@ -85,7 +87,22 @@ const AutoRowWithGap = styled(AutoRow)`
8587
gap: 16px;
8688
`
8789

88-
export const ChunkLoadError = (): ReactNode => {
90+
const IdText = styled(ThemedText.Main)`
91+
opacity: 0.7;
92+
`
93+
94+
const IdRow = styled.div`
95+
display: flex;
96+
align-items: center;
97+
gap: 8px;
98+
flex-wrap: wrap;
99+
`
100+
101+
interface ChunkLoadErrorProps {
102+
eventId: string
103+
}
104+
105+
export const ChunkLoadError = ({ eventId }: ChunkLoadErrorProps): ReactNode => {
89106
const reloadPage = useCallback(() => {
90107
window.location.reload()
91108
}, [])
@@ -108,6 +125,12 @@ export const ChunkLoadError = (): ReactNode => {
108125
This could have happened due to the lack of internet or the release of a new version of the application.
109126
</Trans>
110127
</p>
128+
{eventId && (
129+
<IdRow>
130+
<IdText fontSize={14}>Event ID:</IdText>
131+
<CopyHelper toCopy={eventId}>{eventId}</CopyHelper>
132+
</IdRow>
133+
)}
111134
</NoConnectionDesc>
112135
{cowNoConnectionIMGCache && <NoConnectionImg src={cowNoConnectionIMGCache} alt={t`CowSwap no connection`} />}
113136
</NoConnectionContainer>

apps/cowswap-frontend/src/legacy/components/ErrorBoundary/ErrorWithStackTrace.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import styled from 'styled-components/macro'
1111
import { ThemedText } from 'theme'
1212

1313
import { AutoColumn } from 'legacy/components/Column'
14+
import CopyHelper from 'legacy/components/Copy'
1415

1516
// eslint-disable-next-line import/no-internal-modules -- Direct import to avoid circular dependency (barrel re-exports App which imports ErrorBoundary)
1617
import { Title } from 'modules/application/pure/Page'
@@ -61,12 +62,28 @@ const LinkWrapper = styled.div`
6162
padding: 6px 24px;
6263
`
6364

65+
const IdText = styled(ThemedText.Main)`
66+
opacity: 0.7;
67+
`
68+
69+
const IdRow = styled.div`
70+
display: flex;
71+
align-items: center;
72+
gap: 8px;
73+
flex-wrap: wrap;
74+
`
75+
6476
function truncate(value?: string): string | undefined {
6577
return value ? value.slice(0, 1000) : undefined
6678
}
6779

68-
export const ErrorWithStackTrace = ({ error }: { error: Error }): ReactNode => {
69-
const encodedBody = encodeURIComponent(issueBody(error))
80+
interface ErrorWithStackTraceProps {
81+
error: Error
82+
eventId: string
83+
}
84+
85+
export const ErrorWithStackTrace = ({ error, eventId }: ErrorWithStackTraceProps): ReactNode => {
86+
const encodedBody = encodeURIComponent(issueBody(error, eventId))
7087

7188
return (
7289
<>
@@ -77,6 +94,12 @@ export const ErrorWithStackTrace = ({ error }: { error: Error }): ReactNode => {
7794
<img src={CowError} alt={t`CowSwap Error`} height="125" />
7895
</FlexContainer>
7996
<AutoColumn gap={'md'}>
97+
{eventId && (
98+
<IdRow>
99+
<IdText fontSize={14}>Event ID:</IdText>
100+
<CopyHelper toCopy={eventId}>{eventId}</CopyHelper>
101+
</IdRow>
102+
)}
80103
<CodeBlockWrapper>
81104
<code>
82105
<ThemedText.Main fontSize={10}>
@@ -91,7 +114,7 @@ export const ErrorWithStackTrace = ({ error }: { error: Error }): ReactNode => {
91114
href={
92115
CODE_LINK +
93116
`/issues/new?assignees=&labels=🐞 Bug,🔥 Critical&body=${encodedBody}&title=${encodeURIComponent(
94-
`Crash report: \`${error.name}${error.message && `: ${truncate(error.message)}`}\``,
117+
`Crash report${eventId ? ` [${eventId}]` : ''}: \`${error.name}${error.message && `: ${truncate(error.message)}`}\``,
95118
)}`
96119
}
97120
>
@@ -115,12 +138,21 @@ export const ErrorWithStackTrace = ({ error }: { error: Error }): ReactNode => {
115138
)
116139
}
117140

118-
function issueBody(error: Error): string {
141+
function issueBody(error: Error, eventId: string): string {
119142
const deviceData = userAgent
143+
const sentryEventUrl = `https://cowprotocol.sentry.io/issues/?query=${encodeURIComponent(`id:${eventId}`)}`
120144
return `## URL
121145
122146
${window.location.href}
123147
148+
## Sentry Event ID
149+
150+
\`\`\`
151+
${eventId}
152+
\`\`\`
153+
154+
${sentryEventUrl}
155+
124156
${
125157
error.name &&
126158
`## Error

apps/cowswap-frontend/src/legacy/components/ErrorBoundary/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, E
106106
showDialog={false}
107107
// TODO: Extract nested component outside render function
108108
// eslint-disable-next-line react/no-unstable-nested-components
109-
fallback={({ error: sentryError }) => {
109+
fallback={({ error: sentryError, eventId }) => {
110110
document.body.classList.remove('noScroll')
111111
const { error: localError } = this.state
112112
const error = localError || sentryError
@@ -128,7 +128,13 @@ export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, E
128128
</HeaderWrapper>
129129
)}
130130

131-
<Wrapper>{isChunkLoadError ? <ChunkLoadError /> : <ErrorWithStackTrace error={error} />}</Wrapper>
131+
<Wrapper>
132+
{isChunkLoadError ? (
133+
<ChunkLoadError eventId={eventId} />
134+
) : (
135+
<ErrorWithStackTrace error={error} eventId={eventId} />
136+
)}
137+
</Wrapper>
132138
</AppWrapper>
133139
)
134140
}}

0 commit comments

Comments
 (0)