fix(render): pipeable stream errors not handled (#2781)

Co-authored-by: gabriel miranda <gabrielmfern@outlook.com>
This commit is contained in:
Bu Kinoshita
2026-01-07 11:58:33 -03:00
committed by GitHub
parent a5321f6786
commit 12ff166499
3 changed files with 37 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@react-email/render": patch
---
fix pipeable stream errors not being handled
@@ -156,6 +156,31 @@ describe('readStream', () => {
});
});
describe('PipeableStream error handling', () => {
it('should reject when the source PipeableStream errors', async () => {
let hasError = false;
const erroringStream = new Readable({
read() {
if (!hasError) {
this.push(Buffer.from('<html>'));
hasError = true;
setImmediate(() => {
this.destroy(new Error('Streaming failed'));
});
}
},
});
const pipeableStream = {
pipe: (writable: any) => erroringStream.pipe(writable),
};
await expect(readStream(pipeableStream as any)).rejects.toThrow(
'Streaming failed',
);
});
});
describe('ReadableStream (pipeTo) path', () => {
it('handles multi-byte characters with ReadableStream', async () => {
const japaneseText = 'バクラクのメールテンプレートでスケジュール確認';
+7 -2
View File
@@ -39,13 +39,18 @@ export const readStream = async (
callback();
},
});
stream.pipe(writable);
await new Promise<void>((resolve, reject) => {
writable.on('pipe', (source) => {
source.on('error', (err: Error) => {
writable.destroy(err);
});
});
writable.on('error', reject);
writable.on('close', () => {
resolve();
});
stream.pipe(writable);
});
}