@@ -2203,18 +2203,29 @@ static void WriteBuffers(const FunctionCallbackInfo<Value>& args) {
22032203 iovs[i] = uv_buf_init (Buffer::Data (chunk), Buffer::Length (chunk));
22042204 }
22052205
2206- FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
2207- if ( req_wrap_async != nullptr ) { // writeBuffers(fd, chunks, pos, req)
2206+ if (argc > 3 ) { // writeBuffers(fd, chunks, pos, req)
2207+ FSReqBase* req_wrap_async = GetReqWrap (args, 3 );
22082208 FS_ASYNC_TRACE_BEGIN0 (UV_FS_WRITE, req_wrap_async)
2209- AsyncCall (env, req_wrap_async, args, " write" , UTF8, AfterInteger,
2210- uv_fs_write, fd, *iovs, iovs.length (), pos);
2211- } else { // writeBuffers(fd, chunks, pos, undefined, ctx)
2212- CHECK_EQ (argc, 5 );
2213- FSReqWrapSync req_wrap_sync;
2209+ AsyncCall (env,
2210+ req_wrap_async,
2211+ args,
2212+ " write" ,
2213+ UTF8,
2214+ AfterInteger,
2215+ uv_fs_write,
2216+ fd,
2217+ *iovs,
2218+ iovs.length (),
2219+ pos);
2220+ } else { // writeBuffers(fd, chunks, pos)
2221+ FSReqWrapSync req_wrap_sync (" write" );
22142222 FS_SYNC_TRACE_BEGIN (write);
2215- int bytesWritten = SyncCall (env, args[ 4 ], &req_wrap_sync, " write " ,
2216- uv_fs_write, fd, *iovs, iovs.length (), pos);
2223+ int bytesWritten = SyncCallAndThrowOnError (
2224+ env, &req_wrap_sync, uv_fs_write, fd, *iovs, iovs.length (), pos);
22172225 FS_SYNC_TRACE_END (write, " bytesWritten" , bytesWritten);
2226+ if (is_uv_error (bytesWritten)) {
2227+ return ;
2228+ }
22182229 args.GetReturnValue ().Set (bytesWritten);
22192230 }
22202231}
0 commit comments