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

ERR_SOCKET_BAD_PORT's static-typed error is not affected by validatePort's allowZero value #32857

Closed
soggychips opened this issue Apr 14, 2020 · 1 comment

Comments

@soggychips
Copy link

  • Version: v13.1.0
  • Platform: GNU/Linux
  • Subsystem: internal/validators.js, internal/errors.js, and subsequently dgram.js

What steps will reproduce the bug?

  1. Socket.send and Socket.connect from dgram.js use a function called validatePort, pulled from internal/validators.js

  2. validatePort takes in an optional options argument, w/ a variable allowZero, which defaults to true.

  3. ERR_SOCKET_BAD_PORT (internal/errors.js) returns an error w/ string '%s should be >= 0 and < 65536. Received %s.' and a RangeError

  4. dgram.js calls validatePort with allowZero set to false, which produces the illogical error:

    • RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received 0.

(The illogical part is that the >= does not change to > when allowZero is set to true.)

How often does it reproduce? Is there a required condition?

Always. Call validatePort with port value of 0, with allowZero set to false.

const { validatePort } = require('internal/validators');
let port = 0;
port = validatePort(port, 'Port', { allowZero: false });

What is the expected behavior?

The error message should have the capability to change the hard-coded >= sign to a >

What do you see instead?

RangeError [ERR_SOCKET_BAD_PORT]: Port should be >= 0 and < 65536. Received 0.

Additional information

@soggychips soggychips changed the title ERR_SOCKET_BAD_PORT's error is not affected by validatePort's allowZero value ERR_SOCKET_BAD_PORT's static-typed error is not affected by validatePort's allowZero value Apr 14, 2020
@rickyes
Copy link
Contributor

rickyes commented Apr 15, 2020

I'm working on this.

targos pushed a commit that referenced this issue May 4, 2020
PR-URL: #32861
Fixes: #32857
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this issue May 7, 2020
PR-URL: #32861
Fixes: #32857
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this issue May 13, 2020
PR-URL: #32861
Fixes: #32857
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants