Skip to content

Commit 1f9932d

Browse files
committed
only parse the error message in the ErrorOverlay
1 parent 0c7e6a8 commit 1f9932d

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

packages/preview-server/src/actions/render-email-by-path.tsx

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,35 +192,14 @@ export const renderEmailByPath = async (
192192
stack = ` at ${sourceFile}:${sourceLine}\n${stack}`;
193193
}
194194

195-
const match = cause.msg.match(
196-
/(Unexpected closing tag "[^"]+". It may happen when the tag has already been closed by another tag). (For more info see) (.+)/,
197-
);
198-
if (match) {
199-
const [_, errorMessage, moreInfo, link] = match;
200-
return {
201-
error: {
202-
name: exception.name,
203-
message: (
204-
<>
205-
{errorMessage}.
206-
<p className="text-lg">
207-
{moreInfo}{' '}
208-
<a
209-
className="underline"
210-
rel="noreferrer"
211-
target="_blank"
212-
href={link}
213-
>
214-
{link}
215-
</a>
216-
</p>
217-
</>
218-
),
219-
stack,
220-
cause: error.cause ? JSON.parse(JSON.stringify(cause)) : undefined,
221-
},
222-
};
223-
}
195+
return {
196+
error: {
197+
name: exception.name,
198+
message: cause.msg,
199+
stack,
200+
cause: error.cause ? JSON.parse(JSON.stringify(cause)) : undefined,
201+
},
202+
};
224203
}
225204

226205
return {

packages/preview-server/src/app/preview/[...slug]/error-overlay.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
'use client';
22
import type { ErrorObject } from '../../../utils/types/error-object';
33

4-
export const ErrorOverlay = (props: { error: ErrorObject }) => {
4+
interface ErrorOverlayProps {
5+
error: ErrorObject;
6+
}
7+
8+
const Message = ({ children: content }: { children: string }) => {
9+
const match = content.match(
10+
/(Unexpected closing tag "[^"]+". It may happen when the tag has already been closed by another tag). (For more info see) (.+)/,
11+
);
12+
if (match) {
13+
const [_, errorMessage, moreInfo, link] = match;
14+
return (
15+
<>
16+
{errorMessage}.
17+
<p className="text-lg">
18+
{moreInfo}{' '}
19+
<a className="underline" rel="noreferrer" target="_blank" href={link}>
20+
{link}
21+
</a>
22+
</p>
23+
</>
24+
);
25+
}
26+
return content;
27+
};
28+
29+
export const ErrorOverlay = ({ error }: ErrorOverlayProps) => {
530
return (
631
<>
732
<div className="absolute inset-0 z-50 bg-black/80" />
@@ -16,12 +41,12 @@ export const ErrorOverlay = (props: { error: ErrorObject }) => {
1641
<div className="bg-red-500 h-3" />
1742
<div className="flex flex-grow p-6 min-w-0 max-w-full flex-col space-y-1.5">
1843
<div className="flex-shrink pb-2 text-xl tracking-tight">
19-
<b>{props.error.name}</b>: {props.error.message}
44+
<b>{error.name}</b>: <Message>{error.message}</Message>
2045
</div>
21-
{props.error.stack ? (
46+
{error.stack ? (
2247
<div className="flex-grow scroll-px-4 overflow-x-auto rounded-lg bg-black p-2 text-gray-100">
2348
<pre className="w-full min-w-0 font-mono leading-6 selection:!text-cyan-12 text-xs">
24-
{props.error.stack}
49+
{error.stack}
2550
</pre>
2651
</div>
2752
) : undefined}

packages/preview-server/src/utils/types/error-object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export interface ErrorObject {
77
name: string;
88
stack: string | undefined;
99
cause?: unknown;
10-
message: React.ReactNode;
10+
message: string;
1111
}

0 commit comments

Comments
 (0)