Skip to content

tty.js -> RangeError [ERR_INVALID_FD]: "fd" must be a positive integer: [object Object] #28590

Description

@ORESoftware

Nodejs version 12

import {ReadStream} from "tty";

const fd = fs.openSync('/dev/tty', 'r+');

console.log({fd});

const strm = new ReadStream({fd});

strm.setRawMode(true);

strm.on('data', (d: any) => {
  console.log({d});
});

I get this error:

tty.js:44
    throw new ERR_INVALID_FD(fd);
    ^

RangeError [ERR_INVALID_FD]: "fd" must be a positive integer: [object Object]
    at new ReadStream (tty.js:44:11)
    at Object.<anonymous> (/Users/alex/codes/ores/bunion/dist/cli.js:322:14)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)
    at Function.Module._load (internal/modules/cjs/loader.js:620:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
    at internal/main/run_main_module.js:21:11

I can't figure out why. The fd from the open() call is a positive integer.

It's also, of course, a little suboptimal to have [object Object] instead of an inspected object, so at the very least that's a bug/improvement to make.

Activity

  1. addaleax commented on Jul 7, 2019

    @addaleax
    Member

    const strm = new ReadStream({fd});

    const strm = new ReadStream(fd); without the {...} should help :)

  2. ORESoftware commented on Jul 7, 2019

    @ORESoftware
    ContributorAuthor

    Yeah but according to the TypeScript types, there is an options object, that should take {fd:fd}, here is a link to it: node_modules/@types/node/base.d.ts

    Also, if setRawMode(true) does not return the instance (this), should I file a ticket for that and do you know where that call is? I would like to patch that.

  3. ORESoftware commented on Jul 7, 2019

    @ORESoftware
    ContributorAuthor

    yeah so it's just that the TS typings are off, so I should just move this to TS github repo huh

  4. addaleax commented on Jul 7, 2019

    @addaleax
    Member

    @ORESoftware That’s an issue with the TypeScript then, so yeah, moving is a good idea :)

    Also, if setRawMode(true) does not return the instance (this), should I file a ticket for that and do you know where that call is? I would like to patch that.

    It does, since 1f4d4c0, i.e. since 10.12.0 :)

  5. ORESoftware commented on Jul 7, 2019

    @ORESoftware
    ContributorAuthor

    ok cool, will close thanks

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions