Skip to content

Instantly share code, notes, and snippets.

@nickstenning
Created July 14, 2010 12:12
Show Gist options
  • Select an option

  • Save nickstenning/475340 to your computer and use it in GitHub Desktop.

Select an option

Save nickstenning/475340 to your computer and use it in GitHub Desktop.
var fs = require('fs'),
sys = require('sys');
fs.writeFileSync('foo-sync', '', 'utf8');
try {
fs.writeFile('foo-async', '', 'utf8', function (err) {
if (err) sys.puts("callback caught: " + sys.inspect(err));
});
} catch(e) {
sys.puts("try/catch caught: " + sys.inspect(e));
}
// Expected behaviour
// Create two files, throwing no errors. Or at the very least, if an error is thrown, it should be
// catchable by one of the two methods shown above -- presumably the callback method.
//
// Actual behaviour
// Two files are indeed created, but the following error is thrown, and is uncatchable:
//
// buffer:60
// return this.utf8Write(string, offset);
// ^
// TypeError: Offset is out of bounds
// at Buffer.write (buffer:60:19)
// at fs:387:52
// at node.js:255:9
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment