Skip to content

Commit 78d2197

Browse files
mhartconico974
andauthored
Improve error handling in Writable stream (#1035)
* Improve error handling in Writable stream Ensure errors are correctly handled in the Writable stream write. Previously this would throw an unhandled exception if the response stream had closed (eg, connection had been terminated). This is handled correctly if Node.js 24 stream behaviour is used, but not Node.js 22 or earlier. Returning the callback with the error ensures consistent behaviour for all Node.js versions (or compat versions) * Fix typing * Fix typings again! * Improve error handling in Writable stream Enhance error handling specifically for cloudflare node converters. --------- Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
1 parent 18a8f3a commit 78d2197

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/tall-carpets-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
Improve error handling in Writable stream in cloudflare node converters

packages/open-next/src/overrides/wrappers/cloudflare-node.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
8383

8484
return new Writable({
8585
write(chunk, encoding, callback) {
86-
controller.enqueue(chunk);
86+
try {
87+
controller.enqueue(chunk);
88+
} catch (e: any) {
89+
return callback(e);
90+
}
8791
callback();
8892
},
8993
final(callback) {

0 commit comments

Comments
 (0)