{"record":{"id":"0dd00c7f7e984876","repo":"affaan-m/ECC","slug":"invalid-port-value-portvalue","errorCode":null,"errorMessage":"Invalid --port value: ${portValue}","messagePattern":"Invalid --port value: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/control-pane/server.js","lineNumber":70,"sourceCode":"}\n\nfunction pathValueAfter(args, name) {\n  const value = valueAfter(args, name);\n  if (value === null) return null;\n  if (!value || value.startsWith('-')) {\n    throw new Error(`Invalid ${name} value: expected a path`);\n  }\n  return value;\n}\n\nfunction parseArgs(argv) {\n  const args = argv.slice(2);\n  const help = args.includes('--help') || args.includes('-h');\n  const host = valueAfter(args, '--host') || '127.0.0.1';\n  const portValue = valueAfter(args, '--port') || '8765';\n  const port = Number.parseInt(portValue, 10);\n  if (!Number.isFinite(port) || port < 0 || port > 65535) {\n    throw new Error(`Invalid --port value: ${portValue}`);\n  }\n\n  return {\n    help,\n    host,\n    port,\n    dbPath: valueAfter(args, '--db'),\n    stateDbPath: pathValueAfter(args, '--state-db'),\n    configPath: valueAfter(args, '--config'),\n    query: valueAfter(args, '--query') || '',\n    openBrowser: !args.includes('--no-open'),\n    allowActions: !args.includes('--read-only')\n  };\n}\n\nfunction sendJson(res, statusCode, payload) {\n  const body = JSON.stringify(payload, null, 2);\n  res.writeHead(statusCode, {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/control-pane/server.js#L52-L88","documentation":"Thrown by parseArgs at scripts/lib/control-pane/server.js:67-71 when the --port value cannot be parsed as a finite integer in [0, 65535]. The default port is 8765 (server.js:67) when --port is absent, so this only fires when --port is supplied with a malformed value. Number.parseInt is base-10; NaN, negatives, and values above 65535 are all rejected. Note that the check does not reserved-block privileged ports — port 80 or 1024 will pass the validator; binding will then fail separately if the user lacks capabilities.","triggerScenarios":"`--port abc`; `--port 70000`; `--port -1`; `--port 3.14` (parseInt yields 3, which is actually valid — but `--port 0x10` yields 0 because parseInt(_, 10) stops at 'x', also valid); `--port 99999999999`. Any value where Number.isFinite(port) is false or port is outside [0, 65535].","commonSituations":"Operator typo (`--port 8865` intended, typed `--port 88f65`); copy/paste of a port from a URL with the protocol attached (`--port https://...`); a config script passing a stringly-typed value; intending to use port 0 (OS-assigned) which IS allowed and not the source of the error — the error is for out-of-range/non-numeric.","solutions":["Pass a base-10 integer in [0, 65535]: `--port 8765`.","Omit --port to use the default 8765.","Use `--port 0` if you want the OS to assign a free port (the server reports the actual port via the `url` getter at server.js:336-340).","Sanitize upstream: in a wrapper, validate with `[ \"$P\" -ge 0 ] && [ \"$P\" -le 65535 ]` before forwarding."],"exampleFix":"// before\n$ node scripts/control-pane.js --port 99999\n// after\n$ node scripts/control-pane.js --port 8765","handlingStrategy":"validation","validationCode":"function parsePort(value, fallback = 8765) {\n  if (value == null) return fallback;\n  const p = Number.parseInt(value, 10);\n  if (!Number.isFinite(p) || p < 0 || p > 65535) {\n    throw new Error(`Invalid --port value: ${value}`);\n  }\n  return p;\n}\nparsePort(process.env.CONTROL_PANE_PORT, 8765);","typeGuard":"function isValidPortNumber(value) {\n  return Number.isInteger(value) && value >= 0 && value <= 65535;\n}","tryCatchPattern":null,"preventionTips":["Validate port with isValidPortNumber in the wrapper before invoking control-pane.js.","Default to 8765 (omit --port) when no override is needed.","Use --port 0 deliberately when you want the OS to assign a free port, then read the actual port from the server's url getter."],"tags":["control-pane","validation","cli","network","port","arguments"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}