GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: call the callback with an error if writeSync fails · nodejs/node@19fde63

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/fs
    • sync_write_stream.js
  • test/parallel
    • test-internal-fs-syncwritestream.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fs/sync_write_stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/sync_write_stream.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ ObjectSetPrototypeOf(SyncWriteStream.prototype, Writable.prototype);
2323
ObjectSetPrototypeOf(SyncWriteStream, Writable);
2424

2525
SyncWriteStream.prototype._write = function(chunk, encoding, cb) {
26-
writeSync(this.fd, chunk, 0, chunk.length);
26+
try {
27+
writeSync(this.fd, chunk, 0, chunk.length);
28+
} catch (e) {
29+
cb(e);
30+
return;
31+
}
2732
cb();
2833
};
2934

Collapse file

‎test/parallel/test-internal-fs-syncwritestream.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-internal-fs-syncwritestream.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ const filename = path.join(tmpdir.path, 'sync-write-stream.txt');
7979
assert.strictEqual(stream.fd, null);
8080
}));
8181
}
82+
83+
// Verify that an error on _write() triggers an 'error' event.
84+
{
85+
const fd = fs.openSync(filename, 'w');
86+
const stream = new SyncWriteStream(fd);
87+
88+
assert.strictEqual(stream.fd, fd);
89+
stream._write({}, null, common.mustCall((err) => {
90+
assert(err);
91+
fs.closeSync(fd);
92+
}));
93+
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.