Skip to content

fs.createWriteStream TypeError with new io.js v2.3.0 #1981

Description

@bricss

Activity

  1. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    Could be related to: 353e26e 8357c50

    @yosuke-furukawa

  2. added
    fsIssues and PRs related to file-system APIs and the fs module.
    on Jun 15, 2015
  3. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    I will test this later today.

  4. targos commented on Jun 15, 2015

    @targos
    Member

    It is indeed related to 353e26e.

    karma-html-reporter is using fs.createWriteStream with a callback, which is not supported and AFAIK has never been. This sudden error is uncovering a bug that needs to be fixed in the module.

  5. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    True.
    https://iojs.org/api/fs.html#fs_fs_createwritestream_path_options says nothing about callbacks, so that's not supported.

  6. bricss commented on Jun 15, 2015

    @bricss
    ContributorAuthor

    Yep, they should fix this bug with close event.

  7. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    Still, it might be sensible to add a work-around for that on the io.js side.

  8. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    Some other places:

    g/gist-backup-1.0.0.tgz/gist-backup.js:                    request(raw_url).pipe(fs.createWriteStream(dir + '/' + filename, function (error) {
    m/mecano-0.4.1.tgz/lib/download.js:            return fs.createWriteStream(null, stageDestination, function(err, ws) {
    m/mecano-0.4.1.tgz/lib/download.js:        return fs.createWriteStream(null, stageDestination, function(err, ws) {
    m/mecano-0.4.1.tgz/lib/upload.js:        return fs.createWriteStream(options.ssh, options.destination, function(err, ws) {
    
  9. targos commented on Jun 15, 2015

    @targos
    Member

    mecano is not using the fs module, but ssh2-fs instead. This library seems to accept a callback in createWriteStream

  10. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    Ah, ok. And for gist-backup I filed an issue.
    Btw, that's not a full modules list.

  11. targos commented on Jun 15, 2015

    @targos
    Member

    Btw, that's not a full modules list.

    Yes I understand that, but anyway a module that is using a callback to check for error is wrong. It should listen for the error event, like with any stream.

  12. cjihrig commented on Jun 15, 2015

    @cjihrig
    Contributor

    We may want to revert 353e26e. It should have landed on the next branch, not master. It was also never properly signed off by anyone, even though the commit message says that I did.

  13. targos commented on Jun 15, 2015

    @targos
    Member

    @cjihrig I agree. Even though it is wrong (and useless) to pass anything other than an object to these functions, it is still a breaking change.

  14. targos commented on Jun 15, 2015

    @targos
    Member

    But the PR also added this part:

    else if (typeof options === 'string')
      options = { encoding: options };
    

    so reverting it would break code relying on this new functionality...

  15. ChALkeR commented on Jun 15, 2015

    @ChALkeR
    Member

    I suggest we could fix that instead.
    A simple check on whether the second argument is a function might work.

  16. 4 remaining items

  17. yosuke-furukawa commented on Jun 15, 2015

    @yosuke-furukawa
    Member

    -1 on revert.

    If revert this, we got the fs.createReadStream error again. #1412

    This does not break compatible. We should check the arguments properly.
    If the argument is wrong, we should assert the illegal arguments.

  18. chrisdickinson commented on Jun 15, 2015

    @chrisdickinson
    Contributor

    @yosuke-furukawa brings up a good point – will more code break if we revert back to the original behavior than if we leave the change in? I suppose it boils down to: are more people erroneously passing strings to createReadStream, or are more people erroneously passing functions to createReadStream?

    I am leaning towards patching the typeof options check to also allow function, and to treat it as an options object. We might look into what folks expect passing a function should do, also, so we can determine whether it's worth supporting that!

  19. brendanashworth commented on Jun 16, 2015

    @brendanashworth
    Contributor

    Please allow both rather than only reverting one (and breaking new functionality) or leaving it in (and breaking existing functionality). Since we know it'd break something, it'd be semver-major!

  20. trevnorris commented on Jun 16, 2015

    @trevnorris
    Contributor

    Ridiculous solution: if they pass a callback then create a new Error('no passing a callback!') pass that to the callback and return early.

  21. ChALkeR commented on Jun 16, 2015

    @ChALkeR
    Member

    @trevnorris That would still be a breaking change.

  22. bricss commented on Jun 16, 2015

    @bricss
    ContributorAuthor

    Maybe it would be better to just ignore everything except strings and objects as an options?

  23. yosuke-furukawa commented on Jun 16, 2015

    @yosuke-furukawa
    Member

    -1: ignore
    -1: revert
    +0.5: replace error to deprecation #1982

    We should know what is the expected behavior when user calls fs.createWritableStream('example.txt', function(){}).

    And we write the specification, we should follow the spec. we should not support the illegal function call.
    https://iojs.org/api/fs.html#fs_fs_createreadstream_path_options

    If this is breaking change, we already broke fs.createReadStream here. #635 #1412
    this PR is landed in 1.5.0, it is not 2.0.0.

  24. bnoordhuis commented on Jun 17, 2015

    @bnoordhuis
    Member

    Just my EUR .02 but the broken modules are broken because they are buggy. I don't see any reason to revert the change or add workarounds, just PR the offenders as a courtesy and move on.

  25. ChALkeR commented on Jun 17, 2015

    @ChALkeR
    Member

    @bnoordhuis One module is already fixed, and @targos already filed a PR for the second one.
    I don't know if there are more. Also, see #1998.

    Edit: mentioned the wrong person, fixed. Sorry.

  26. cjihrig commented on Jun 17, 2015

    @cjihrig
    Contributor

    I'd also rather fix the couple broken modules than land #1998 and #1982.

  27. Fishrock123 commented on Jun 17, 2015

    @Fishrock123
    Contributor

    Yeah, I'm not so sure I like either also.

  28. ChALkeR commented on Jun 17, 2015

    @ChALkeR
    Member

    Ok, as no one (including myself) seems to actually support the idea of handling this (wrong API usage by modules) on the io.js side, I am closing both #1982 and #1998 PRs and this issue.

    This is a bug in the module that is using the API in an incorrect and unsupported way.

    A pull request targeting karma-html-reporter is here: dtabuenc/karma-html-reporter#27 (thanks, @targos), karma-html-reporter should merge it to solve its problem.

    If anyone of @nodejs/collaborators thinks that this should be reopened or that there needs to be more discussion on this matter, just leave a message here.

  29. yosuke-furukawa commented on Jun 17, 2015

    @yosuke-furukawa
    Member

    @ChALkeR @bnoordhuis @cjihrig
    Thank you soooo much. I agreed bnoordhuis and cjihrig's idea.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.invalidIssues and PRs that are invalid.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions