Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ORESoftware opened this issue Jul 7, 2019 · 5 comments

Comments

@ORESoftware
Copy link
Contributor

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.

@addaleax
Copy link
Member

addaleax commented Jul 7, 2019

const strm = new ReadStream({fd});

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

@ORESoftware
Copy link
Contributor Author

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.

@ORESoftware
Copy link
Contributor Author

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

@addaleax
Copy link
Member

addaleax commented Jul 7, 2019

@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 :)

@ORESoftware
Copy link
Contributor Author

ok cool, will close thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants