Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Bad argument TypeError (using fs.createWriteStream) #6

Closed
klipstein opened this Issue Apr 9, 2012 · 9 comments

Comments

Projects
None yet
4 participants

When I use a file write-stream in one of my modules and graceful-fs is loaded somewhere else it breaks the writing to that filestream with:

fs.js:307
  binding.write(fd, buffer, offset, length, position, wrapper);
          ^
TypeError: Bad argument
    at [object Object].<anonymous> (fs.js:307:11)
    at [object Object].flush (fs.js:1312:10)
    at Object.oncomplete (fs.js:1304:10)

Here a simplified example how you can reproduce this error (using node version 0.6.14).

var fs = require('fs');
var stream = fs.createWriteStream('foo.txt');
// could be loaded in another module (e.g. rimraf)
require('graceful-fs');
stream.write('foo');

I've stumpled upon this issue after doing npm install with a newer npm version (Version 1.1.5) on a project where rimraf is used.

With version 1.1.15 of npm it somehow installed the optionalDependencies (https://github.com/isaacs/rimraf/blob/master/package.json#L8) of rimraf and I didn't found any reference how to avoid the installation of this optional dependency. Maybe this should be reported to the npm project directly?

Owner

isaacs commented Apr 9, 2012

This is a known issue, but I haven't had a chance to track it down.

As a workaround, load graceful-fs before creating the stream object, or after its 'open' event, and it works fine.

@isaacs isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Apr 9, 2012

@isaacs isaacs fs.WriteStream: Handle modifications to fs.open
If the fs.open method is modified via AOP-style extension, in between
the creation of an fs.WriteStream and the processing of its action
queue, then the test of whether or not the method === fs.open will fail,
because fs.open has been replaced.

The solution is to save a reference to fs.open on the stream itself when
the action is placed in the queue.

This fixes isaacs/node-graceful-fs#6.
06ada03

@isaacs isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Apr 9, 2012

@isaacs isaacs fs.WriteStream: Handle modifications to fs.open
If the fs.open method is modified via AOP-style extension, in between
the creation of an fs.WriteStream and the processing of its action
queue, then the test of whether or not the method === fs.open will fail,
because fs.open has been replaced.

The solution is to save a reference to fs.open on the stream itself when
the action is placed in the queue.

This fixes isaacs/node-graceful-fs#6.
c75f71d
Owner

isaacs commented Apr 9, 2012

Fixed in node 0.6.15 (released today) and 0.7.8 (next release)

@isaacs isaacs closed this Apr 9, 2012

Wow, that was a quick fix. Just installed node 0.6.15 and I can confirm that it fixed this issue. Thank you Isaac.

@paulmillr paulmillr referenced this issue in brunch/brunch Jul 27, 2012

Closed

Random Bad Argument Errors with Mocha #382

damassi commented Jul 27, 2012

Re issue #382 above: This error is happening on my side as well, but adding in this line:

if( fd === null || cb === null ) return;

after line 90:

fs.close = function (fd, cb) {

fixes the problem. Thoughts?

Owner

isaacs commented Jul 27, 2012

Why are you calling fs.close() with no fd argument?

damassi commented Jul 27, 2012

To clarify, I'm using Brunch.io, and this package is contained inside of it; @paulmillr recommended that I post here.

Owner

isaacs commented Jul 27, 2012

Commenting on the brunch bug. It has nothing to do with graceful-fs.

fabdrol commented Oct 2, 2012

I have encountered this problem in a totally different context. See my test code at: https://github.com/fabdrol/Downloader
It appears to happen inside fs in node-core

Owner

isaacs commented Oct 2, 2012

@fabdrol Please gist the error you're encountering. Note that the root cause of this issue was fixed in node core, so whatever you're seeing is either a different issue, or can be fixed by upgrading node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment