Skip to content

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

Description

@soggychips
  • 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

Activity

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