You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: throwing error inside emailtheme component not handled
throwing an error inside the emailthemes component was not caught as an error.
This is because react-email/components
didnt handle it correctly and fell back to client side rendering.
This was outside of our try catch code, it was in the actual rendering.
So it came back as status-ok.
We bump versions to the latest version which does throw it.
We also have to update the freestyle mock.
Bun cannot handle these kinds of errors.
they are treated as uncaught exceptions by it.
So we switch to node.
We also refactor some tests because the react-email components now return slightly different messages.
"details": { "error": "{\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:145:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}" },
571
-
"error": "Failed to render email with theme: {\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:145:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}",
572
-
}
573
-
`);
570
+
expect(response.body).toMatchObject({
571
+
code: "EMAIL_RENDERING_ERROR",
572
+
});
573
+
// Error message varies by runtime (Bun vs Node), just check it indicates a type error
<td style="background-color:rgb(250,251,251);font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;line-height:1.5">
"html": "<!DOCTYPE html PUBLIC \\"-//W3C//DTD XHTML 1.0 Transitional//EN\\" \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\"><html dir=\\"ltr\\" lang=\\"en\\"><head></head><body><!--$--><table align=\\"center\\"width=\\"100%\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\" style=\\"max-width:37.5em\\"><tbody><tr style=\\"width:100%\\"><td><div>Preview for <!-- -->John Doe</div></td></tr></tbody></table><!--3--><!--/$--></body></html>",
222
+
"html": "<!DOCTYPE html PUBLIC \\"-//W3C//DTD XHTML 1.0 Transitional//EN\\" \\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\"><html dir=\\"ltr\\" lang=\\"en\\"><head></head><body><!--$--><table border=\\"0\\" width=\\"100%\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\" align=\\"center\\"><tbody><tr><td><table align=\\"center\\" width=\\"100%\\" border=\\"0\\" cellPadding=\\"0\\" cellSpacing=\\"0\\" role=\\"presentation\\" style=\\"max-width:37.5em\\"><tbody><tr style=\\"width:100%\\"><td><div>Preview for <!-- -->John Doe</div></td></tr></tbody></table></td></tr></tbody></table><!--3--><!--/$--></body></html>",
223
223
"notification_category": "Transactional",
224
224
"subject": "Render Draft Subject",
225
225
},
@@ -441,13 +441,10 @@ it("should reject draft that throws an error when rendered", async ({ expect })
441
441
},
442
442
});
443
443
expect(renderRes.status).toBe(400);
444
-
expect(renderRes.body).toMatchInlineSnapshot(`
445
-
{
446
-
"code": "EMAIL_RENDERING_ERROR",
447
-
"details": { "error": "{\\"message\\":\\"Intentional error from draft\\",\\"stack\\":\\"Error: Intentional error from draft\\\\n at EmailTemplate (/app/tmp/job-<stripped UUID>/script.ts:99:13)\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:146:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}" },
448
-
"error": "Failed to render email with theme: {\\"message\\":\\"Intentional error from draft\\",\\"stack\\":\\"Error: Intentional error from draft\\\\n at EmailTemplate (/app/tmp/job-<stripped UUID>/script.ts:99:13)\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:146:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}",
449
-
}
450
-
`);
444
+
expect(renderRes.body).toMatchObject({
445
+
code: "EMAIL_RENDERING_ERROR",
446
+
});
447
+
expect(renderRes.body.error).toContain("Intentional error from draft");
451
448
});
452
449
453
450
it("should reject draft that does not export EmailTemplate function",async({ expect })=>{
@@ -470,13 +467,11 @@ it("should reject draft that does not export EmailTemplate function", async ({ e
470
467
},
471
468
});
472
469
expect(renderRes.status).toBe(400);
473
-
expect(renderRes.body).toMatchInlineSnapshot(`
474
-
{
475
-
"code": "EMAIL_RENDERING_ERROR",
476
-
"details": { "error": "{\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is undefined)\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is undefined)\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:147:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}" },
477
-
"error": "Failed to render email with theme: {\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is undefined)\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is undefined)\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:147:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}",
478
-
}
479
-
`);
470
+
expect(renderRes.body).toMatchObject({
471
+
code: "EMAIL_RENDERING_ERROR",
472
+
});
473
+
// Error message varies by runtime
474
+
expect(renderRes.body.error).toBeDefined();
480
475
});
481
476
482
477
it("should reject draft with invalid JSX syntax",async({ expect })=>{
@@ -567,7 +562,9 @@ it.todo("should reject draft that allocates too much memory", async ({ expect })
567
562
});
568
563
// Should fail due to memory limits, not hang or crash the server
it("should reject draft that exports a non-function",async({ expect })=>{
@@ -587,13 +584,11 @@ it("should reject draft that exports a non-function", async ({ expect }) => {
587
584
},
588
585
});
589
586
expect(renderRes.status).toBe(400);
590
-
expect(renderRes.body).toMatchInlineSnapshot(`
591
-
{
592
-
"code": "EMAIL_RENDERING_ERROR",
593
-
"details": { "error": "{\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:145:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}" },
594
-
"error": "Failed to render email with theme: {\\"message\\":\\"element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\",\\"stack\\":\\"TypeError: element.type is not a function. (In 'element.type(element.props || {})', 'element.type' is \\\\\\"not a function\\\\\\")\\\\n at findComponentValue (/app/tmp/job-<stripped UUID>/script.ts:70:20)\\\\n at <anonymous> (/app/tmp/job-<stripped UUID>/script.ts:145:18)\\\\n at fulfilled (/app/tmp/job-<stripped UUID>/script.ts:32:24)\\"}",
595
-
}
596
-
`);
587
+
expect(renderRes.body).toMatchObject({
588
+
code: "EMAIL_RENDERING_ERROR",
589
+
});
590
+
// Error message varies by runtime
591
+
expect(renderRes.body.error).toBeDefined();
597
592
});
598
593
599
594
it("should reject theme_tsx_source that throws an error when rendered",async({ expect })=>{
@@ -621,7 +616,10 @@ it("should reject theme_tsx_source that throws an error when rendered", async ({
0 commit comments