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,doc: add type-check to isatty #15567

Closed
wants to merge 1 commit into from
Closed

Conversation

bengl
Copy link
Member

@bengl bengl commented Sep 23, 2017

Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

tty, doc

@nodejs-github-bot nodejs-github-bot added the tty Issues and PRs related to the tty subsystem. label Sep 23, 2017
@bengl
Copy link
Member Author

bengl commented Sep 23, 2017

@lpinca
Copy link
Member

lpinca commented Sep 24, 2017

Where does this fall on the semver scale? Bugfix?

@bengl
Copy link
Member Author

bengl commented Sep 24, 2017

@lpinca Yes, I'd call it a patch/bugfix, since it fixes a previously incorrect API.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It would be nice if the messages could be improved though, but it is not a must.


strictEqual(isatty(-1), false, 'number that isn\'t a tty, is');
strictEqual(isatty(5), false, 'number that isn\'t a tty, is');
strictEqual(isatty(1.1), false, 'number that isn\'t a tty, is');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The messages here are somewhat confusing out of my perspective. Maybe write something like e.g.
-1 reported to be a tty but should not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'll clarify these.

@BridgeAR
Copy link
Member

This is definitely semver-patch

> isatty(-2)
/home/ruben/.nvm/versions/node/v8.5.0/bin/node[2433]: ../src/tty_wrap.cc:109:static void node::TTYWrap::IsTTY(const v8::FunctionCallbackInfo<v8::Value>&): Assertion `(fd) >= (0)' failed.
 1: node::Abort() [node]
 2: node::Assert(char const* const (*) [4]) [node]
 3: 0x13e0f97 [node]
 4: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [node]
 5: 0xc1365a [node]
 6: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 7: 0x3d4bf3a846fd
Aborted (core dumped)

@bengl
Copy link
Member Author

bengl commented Sep 24, 2017

@BridgeAR I think the latest change clarifies it?

@BridgeAR
Copy link
Member

Definitely! Thanks a lot

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 25, 2017
@jasnell
Copy link
Member

jasnell commented Sep 25, 2017

Defensively marked as semver-major but I'd be ok with semver-minor or patch.

@BridgeAR
Copy link
Member

@nodejs/tsc please weight in about semver-major / semver-patch.

@BridgeAR BridgeAR requested a review from a team September 26, 2017 04:19
@BridgeAR
Copy link
Member

Ping @nodejs/tsc

@@ -123,4 +123,5 @@ added: v0.5.8
* `fd` {number} A numeric file descriptor

The `tty.isatty()` method returns `true` if the given `fd` is associated with
a TTY and `false` if is not.
a TTY and `false` if it is not, including whenever `fd` is not a non-negative
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there ought to be clearer wording than not a non-negative integer. How about just a negative integer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also be fine with simply removing the additional text here, as a negative number is not a valid fd. But since a negative integer can be returned from a sys call to retrieve a file descriptor if there is an error, I'm OK with leaving it too for explicitness.

@Trott
Copy link
Member

Trott commented Sep 29, 2017

Seems patch to me. I'm in favor of "when in doubt, mark it semver-major" but I'm not seeing any real doubt on this one.

@BridgeAR BridgeAR removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 30, 2017
@BridgeAR
Copy link
Member

BridgeAR commented Oct 1, 2017

@BridgeAR
Copy link
Member

BridgeAR commented Oct 2, 2017

Seems like there are some related failures

https://ci.nodejs.org/job/node-test-commit-osx/12738/nodes=osx1010/console

ok 1753 pseudo-tty/test-stderr-stdout-handle-sigwinch
  ---
  duration_ms: 0.89
  ...
length differs.
expect=0
actual=13
patterns:
outlines:
outline = assert.js:44
outline = throw new errors.AssertionError({
outline = ^
outline = AssertionError [ERR_ASSERTION]: 5 reported to be a tty, but it is not
outline = at Object.<anonymous> (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1010/test/pseudo-tty/test-tty-isatty.js:12:1)
outline = at Module._compile (module.js:600:30)
outline = at Object.Module._extensions..js (module.js:611:10)
outline = at Module.load (module.js:521:32)
outline = at tryModuleLoad (module.js:484:12)
outline = at Function.Module._load (module.js:476:3)
outline = at Function.Module.runMain (module.js:641:10)
outline = at startup (bootstrap_node.js:187:16)
outline = at bootstrap_node.js:605:3
not ok 1754 pseudo-tty/test-tty-isatty
  ---
  duration_ms: 0.79
  severity: fail
  stack: |-
    assert.js:44
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 5 reported to be a tty, but it is not
        at Object.<anonymous> (/Users/iojs/build/workspace/node-test-commit-osx/nodes/osx1010/test/pseudo-tty/test-tty-isatty.js:12:1)
        at Module._compile (module.js:600:30)
        at Object.Module._extensions..js (module.js:611:10)
        at Module.load (module.js:521:32)
        at tryModuleLoad (module.js:484:12)
        at Function.Module._load (module.js:476:3)
        at Function.Module.runMain (module.js:641:10)
        at startup (bootstrap_node.js:187:16)
        at bootstrap_node.js:605:3

@addaleax
Copy link
Member

addaleax commented Oct 4, 2017

+1 to semver-patch

@Fishrock123
Copy link
Contributor

Does process.binding('tty_wrap').isTTY not type-check? How does a non-fd get seen as an fd today by this?

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm I guess

@BridgeAR
Copy link
Member

Ping @bengl

@bengl
Copy link
Member Author

bengl commented Oct 19, 2017

Cool I'll land this later today.

@Fishrock123 process.binding('tty_wrap').isTTY currently does some type-checking: https://github.com/nodejs/node/blob/master/src/tty_wrap.cc#L108-L109

Unfortunately, giving it a negative number results in an abort (#15567 (comment)), which can't be handled in JS. Also, giving it a non-number always returns true, due to Int32Value().

@BridgeAR
Copy link
Member

@bengl the CI reported a error that looked related. See my former comment #15567 (comment).

@bengl
Copy link
Member Author

bengl commented Oct 19, 2017

@BridgeAR Oh weird! I'll take a look at that first.

Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.
@bengl
Copy link
Member Author

bengl commented Oct 19, 2017

Looks like 5 is potentially a pseudo tty in those tests. Switched it to a pretty huge number that shouldn't ever be a pseudo tty in those tests.

New CI: https://ci.nodejs.org/job/node-test-pull-request/10864/

@bengl
Copy link
Member Author

bengl commented Oct 20, 2017

CI failures seem unrelated. @BridgeAR LGTY?

bengl added a commit that referenced this pull request Oct 22, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: #15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@bengl
Copy link
Member Author

bengl commented Oct 22, 2017

Landed in 27e12e7

@bengl bengl closed this Oct 22, 2017
MylesBorins pushed a commit that referenced this pull request Oct 23, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: #15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Oct 26, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: nodejs/node#15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@MylesBorins
Copy link
Contributor

Since this fixes a core dump I've gone ahead and backported to v6.x

please lmk if it should be backed out

MylesBorins pushed a commit that referenced this pull request Nov 16, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: #15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Nov 21, 2017
MylesBorins pushed a commit that referenced this pull request Nov 21, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: #15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
MylesBorins pushed a commit that referenced this pull request Nov 28, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: #15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
Previously, various inputs other than non-negative integers would
produce incorrect results.

Added type-checking on input, returning false for anything other than
non-negative integers.

Also clarified in docs.

PR-URL: nodejs/node#15567
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants