mirror of
https://github.com/resend/react-email.git
synced 2026-09-14 14:18:02 +08:00
fix(render): pipeable stream errors not handled (#2781)
Co-authored-by: gabriel miranda <gabrielmfern@outlook.com>
This commit is contained in:
@@ -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 = 'バクラクのメールテンプレートでスケジュール確認';
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user