{"record":{"id":"4f473d66e734a8e6","repo":"denoland/deno","slug":"invalid-port-expected-number-maybeport","errorCode":null,"errorMessage":"Invalid port (expected number): ${maybePort}","messagePattern":"Invalid port \\(expected number\\): (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/net/01_net.js","lineNumber":645,"sourceCode":"    }\n    case \"tunnel\": {\n      const { 0: rid, 1: addr } = op_net_listen_tunnel();\n      return new Listener(rid, addr, \"tunnel\");\n    }\n    default:\n      throw new TypeError(`Unsupported transport: '${transport}'`);\n  }\n}\n\nfunction validatePort(maybePort, isServer = false) {\n  // A missing port means \"any available port\" (port 0) for servers. Clients\n  // must always specify a port to connect to, so a missing port is left as-is\n  // and rejected below.\n  if (isServer && (maybePort === null || maybePort === undefined)) {\n    maybePort = 0;\n  }\n  if (typeof maybePort !== \"number\" && typeof maybePort !== \"string\") {\n    throw new TypeError(`Invalid port (expected number): ${maybePort}`);\n  }\n  if (maybePort === \"\") throw new TypeError(\"Invalid port: ''\");\n  const port = Number(maybePort);\n  if (!NumberIsInteger(port)) {\n    if (NumberIsNaN(port) && !NumberIsNaN(maybePort)) {\n      throw new TypeError(`Invalid port: '${maybePort}'`);\n    } else {\n      throw new TypeError(`Invalid port: ${maybePort}`);\n    }\n  } else if (port < (isServer ? 0 : 1) || port > 65535) {\n    // Servers may bind to port 0 (OS-assigned), clients may not connect to it.\n    throw new RangeError(`Invalid port (out of range): ${maybePort}`);\n  }\n  return port;\n}\n\nfunction createListenDatagram(udpOpFn, unixOpFn) {\n  return function listenDatagram(args) {","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/net/01_net.js#L627-L663","documentation":"Error \"Invalid port (expected number): ${maybePort}\" thrown in denoland/deno.","triggerScenarios":"Thrown at ext/net/01_net.js:645 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}