1
+ import { Button , Divider , Group , ScrollArea , Text } from "@mantine/core" ;
2
+ import { Box , Paper , Stack , Title } from "@mantine/core" ;
3
+ import { FallbackProps } from "react-error-boundary" ;
4
+ import { Icon } from "../Icon" ;
5
+ import { iconBug , iconCheck , iconCopy , iconReset , iconWarning } from "~/util/icons" ;
6
+ import { adapter } from "~/adapter" ;
7
+ import { useVersionCopy } from "~/hooks/debug" ;
8
+
9
+ export function AppErrorHandler ( { error, resetErrorBoundary } : FallbackProps ) {
10
+ const [ copyDebug , clipboard ] = useVersionCopy ( ) ;
11
+
12
+ const message = error instanceof Error
13
+ ? error . message
14
+ : error ;
15
+
16
+ return (
17
+ < ScrollArea
18
+ h = "100%"
19
+ bg = "slate.9"
20
+ >
21
+ < Paper
22
+ p = "xl"
23
+ maw = { 800 }
24
+ mx = "auto"
25
+ my = { 75 }
26
+ >
27
+ < Stack gap = "lg" >
28
+ < Group c = "bright" >
29
+ < Icon path = { iconWarning } size = "lg" />
30
+ < Title > Surrealist encountered an error</ Title >
31
+ </ Group >
32
+
33
+ < Text >
34
+ You can find a detailed error message below. If you believe this is a bug, please report it on our GitHub repository.
35
+ </ Text >
36
+
37
+ < Group >
38
+ < Button
39
+ leftSection = { < Icon path = { iconReset } /> }
40
+ onClick = { resetErrorBoundary }
41
+ color = "slate"
42
+ radius = "xs"
43
+ size = "xs"
44
+ >
45
+ Restart Surrealist
46
+ </ Button >
47
+ < Button
48
+ leftSection = { < Icon path = { iconBug } /> }
49
+ onClick = { ( ) => adapter . openUrl ( 'https://github.com/surrealdb/surrealist/issues' ) }
50
+ color = "slate"
51
+ radius = "xs"
52
+ size = "xs"
53
+ >
54
+ File an issue
55
+ </ Button >
56
+ < Button
57
+ leftSection = { < Icon path = { clipboard . copied ? iconCheck : iconCopy } /> }
58
+ onClick = { copyDebug }
59
+ color = "slate"
60
+ radius = "xs"
61
+ size = "xs"
62
+ >
63
+ { clipboard . copied ? 'Copied!' : 'Copy version information' }
64
+ </ Button >
65
+ </ Group >
66
+
67
+ < Divider />
68
+
69
+ { message && (
70
+ < Box >
71
+ < Title order = { 3 } >
72
+ Message
73
+ </ Title >
74
+
75
+ < Text
76
+ mt = "xs"
77
+ ff = "mono"
78
+ c = "slate"
79
+ >
80
+ { message }
81
+ </ Text >
82
+ </ Box >
83
+ ) }
84
+
85
+ { error . cause && (
86
+ < Box >
87
+ < Title order = { 3 } >
88
+ Cause
89
+ </ Title >
90
+
91
+ < Box
92
+ mt = "xs"
93
+ ff = "mono"
94
+ c = "slate"
95
+ style = { {
96
+ whiteSpace : 'pre' ,
97
+ overflowX : 'auto' ,
98
+ maxWidth : '90vw' ,
99
+ WebkitUserSelect : 'initial' ,
100
+ userSelect : 'initial'
101
+ } }
102
+ >
103
+ { error . cause }
104
+ </ Box >
105
+ </ Box >
106
+ ) }
107
+
108
+ { error . stack && (
109
+ < Box >
110
+ < Title order = { 3 } >
111
+ Stack trace
112
+ </ Title >
113
+
114
+ < Box
115
+ mt = "xs"
116
+ ff = "mono"
117
+ c = "slate"
118
+ style = { {
119
+ whiteSpace : 'pre' ,
120
+ overflowX : 'auto' ,
121
+ maxWidth : '90vw' ,
122
+ WebkitUserSelect : 'initial' ,
123
+ userSelect : 'initial'
124
+ } }
125
+ >
126
+ { error . stack }
127
+ </ Box >
128
+ </ Box >
129
+ ) }
130
+ </ Stack >
131
+ </ Paper >
132
+ </ ScrollArea >
133
+ // <div style={{
134
+ // width: '100%',
135
+ // display: 'flex',
136
+ // justifyContent: 'center',
137
+ // paddingTop: '50px',
138
+ // }}>
139
+ // <div style={{
140
+ // display: 'flex',
141
+ // flexDirection: 'column',
142
+ // justifyContent: 'center',
143
+ // }}>
144
+ // <h1>Something went wrong!</h1>
145
+ // {error.name && <h2>{error.name}</h2> }
146
+ // <div style={{
147
+ // padding: '0px 10px',
148
+ // border: '1px solid black'
149
+ // }}>
150
+ // <h3>Message</h3>
151
+ // <p style={{
152
+ // whiteSpace: 'pre',
153
+ // overflowX: 'auto',
154
+ // maxWidth: '90vw'
155
+ // }}>
156
+ // {message}
157
+ // </p>
158
+ // </div>
159
+ // {error.cause && (
160
+ // <div style={{
161
+ // padding: '0px 10px',
162
+ // border: '1px solid black',
163
+ // marginTop: '20px',
164
+ // }}>
165
+ // <h3>Cause</h3>
166
+ // <p style={{
167
+ // whiteSpace: 'pre',
168
+ // overflowX: 'auto',
169
+ // maxWidth: '90vw'
170
+ // }}>
171
+ // {error.cause}
172
+ // </p>
173
+ // </div>
174
+ // )}
175
+ // {error.stack && (
176
+ // <div style={{
177
+ // padding: '0px 10px',
178
+ // border: '1px solid black',
179
+ // marginTop: '20px',
180
+ // }}>
181
+ // <h3>Stack trace</h3>
182
+ // <p style={{
183
+ // whiteSpace: 'pre',
184
+ // overflowX: 'auto',
185
+ // maxWidth: '90vw',
186
+ // lineHeight: '30px',
187
+ // }}>
188
+ // {error.stack}
189
+ // </p>
190
+ // </div>
191
+ // )}
192
+ // <div style={{
193
+ // display: 'flex',
194
+ // justifyContent: 'center',
195
+ // marginTop: '40px',
196
+ // }}>
197
+ // <button onClick={resetErrorBoundary} style={{
198
+ // padding: '10px',
199
+ // background: 'black',
200
+ // color: 'white',
201
+ // border: 'none',
202
+ // cursor: 'pointer',
203
+ // fontSize: '16px',
204
+ // fontWeight: '600',
205
+ // }}>
206
+ // Reload Surrealist
207
+ // </button>
208
+ // </div>
209
+ // </div>
210
+ // </div>
211
+ ) ;
212
+ }
0 commit comments