Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bad argument TypeError (using fs.createWriteStream) #6

Closed
klipstein opened this Issue · 9 comments

4 participants

@klipstein

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?

@isaacs
Owner

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 referenced this issue from a commit in isaacs/node
@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 referenced this issue from a commit in isaacs/node
@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
@isaacs
Owner

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

@isaacs isaacs closed this
@klipstein

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

@Skomski Skomski referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@ErikDubbelboer ErikDubbelboer referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@paulmillr paulmillr referenced this issue in brunch/brunch
Closed

Random Bad Argument Errors with Mocha #382

@damassi

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?

@isaacs
Owner

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

@damassi

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

@isaacs
Owner

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

@kanzure kanzure referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@kanzure kanzure referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@fabdrol

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

@isaacs
Owner

@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
Something went wrong with that request. Please try again.