{"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":72,"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":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/control-pane/server.js#L54-L90","documentation":"The control-pane server's parseArgs validates --port: the value is parsed with Number.parseInt and must be a finite number in [0, 65535]. Anything else (non-numeric text, negative, or above 65535) throws 'Invalid --port value: <value>'.","triggerScenarios":"Running `node server.js --port abc`, `--port 99999`, `--port -1`, or `--port 8765x`; also an empty value that falls through to the default would not throw, but any explicit bad value does.","commonSituations":"Copy-pasting a port with stray characters; confusing the port with a PID; using a port above the TCP limit; env substitution producing garbage ($PORT unset with set -u off giving empty string is fine, but a templating bug can inject text).","solutions":["Pass a numeric port between 0 and 65535: --port 8765","Verify the value with: node -e \"const p=parseInt(process.argv[1],10); console.log(Number.isFinite(p)&&p>=0&&p<=65535)\" 8765","Fix the shell variable or template that injects a non-numeric port","Omit --port to use the default 8765"],"exampleFix":"// before\n$ node server.js --port \"8080 \"\n// after\n$ node server.js --port 8080","handlingStrategy":"validation","validationCode":"const port = Number.parseInt(portArg, 10);\nif (!Number.isFinite(port) || port < 0 || port > 65535) throw new Error(`bad port: ${portArg}`);","typeGuard":"const isValidPort = (v) => { const p = Number.parseInt(v, 10); return Number.isFinite(p) && p >= 0 && p <= 65535; };","tryCatchPattern":"try { const opts = parseArgs(process.argv); } catch (e) {\n  if (String(e.message).startsWith('Invalid --port')) console.error('Use a numeric port 0-65535, e.g. --port 8765');\n  else throw e;\n}","preventionTips":["Always pass plain integers to --port","Never confuse port with PID or process count","Validate templated/env-injected ports before launch","Omit --port to accept the default 8765"],"tags":["cli","port","validation"],"backgroundTag":"invalid-flag-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}