{"record":{"id":"250310713f734789","repo":"can1357/oh-my-pi","slug":"port-must-be-1-65535","errorCode":null,"errorMessage":"--port must be 1..65535","messagePattern":"--port must be 1\\.\\.65535","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/metaharness/src/server.ts","lineNumber":89,"sourceCode":"\nconst enum SseState {\n\tOpen = 0,\n\tClosed = 1,\n}\n\ninterface SseClient {\n\tcontroller: ReadableStreamDefaultController<Uint8Array>;\n\tstate: SseState;\n}\n\nfunction parseServerArgs(argv: string[]): { port: number; jobsDir: string } {\n\tlet port = 4700;\n\tlet jobsDir = DEFAULT_JOBS_DIR;\n\tfor (let i = 0; i < argv.length; i++) {\n\t\tif (argv[i] === \"--port\" && argv[i + 1]) port = Number(argv[++i]);\n\t\telse if (argv[i] === \"--jobs-dir\" && argv[i + 1]) jobsDir = path.resolve(argv[++i]);\n\t}\n\tif (!Number.isSafeInteger(port) || port < 1 || port > 65535) throw new Error(\"--port must be 1..65535\");\n\treturn { port, jobsDir };\n}\n\n/** Job names are single path segments; anything else could escape the jobs dir. */\nfunction assertSafeJobName(jobName: string): void {\n\tif (!jobName || jobName === \".\" || jobName === \"..\" || /[/\\\\]/.test(jobName)) {\n\t\tthrow new Error(`invalid job name: ${jobName}`);\n\t}\n}\n\n/** True when `pid` names a live process (signal-0 probe). */\nfunction pidAlive(pid: number | null): boolean {\n\tif (pid == null) return false;\n\ttry {\n\t\tprocess.kill(pid, 0);\n\t\treturn true;\n\t} catch {\n\t\treturn false;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/metaharness/src/server.ts#L71-L107","documentation":"The metaharness server validates the --port CLI argument after parsing: it must be a safe integer between 1 and 65535. Non-numeric, zero, negative, or out-of-range values are rejected with this error before the server starts.","triggerScenarios":"parseServerArgs receives --port followed by a value that Number() maps to something outside 1..65535 — e.g. --port 0, --port 70000, --port abc (NaN), --port 99999999999999 (unsafe integer), or --port with a missing/non-adjacent value.","commonSituations":"Typo in the port number; copying a port from a config that includes a suffix (e.g. '4700x'); scripting that passes an empty or unset variable as the port value; confusing port with a host:port string.","solutions":["Pass a valid numeric port: --port 4700 (any integer 1-65535)","Check for stray characters or whitespace in the port value in scripts/config","Ensure the value immediately follows --port (the parser reads argv[++i])","Use the default by omitting --port entirely (default 4700)"],"exampleFix":"// before\n$ metaharness-server --port 70000\n// Error: --port must be 1..65535\n\n// after\n$ metaharness-server --port 4800","handlingStrategy":"validation","validationCode":"function parsePort(value) {\n  const port = Number(value);\n  if (!Number.isSafeInteger(port) || port < 1 || port > 65535) {\n    throw new Error(`invalid port: ${value}`);\n  }\n  return port;\n}\n// call before spawning: parsePort(process.env.BENCH_PORT ?? \"4700\")","typeGuard":"function isValidPort(v) {\n  return typeof v === \"number\" && Number.isSafeInteger(v) && v >= 1 && v <= 65535;\n}","tryCatchPattern":"try {\n  const server = spawnServer([\"--port\", portArg]);\n} catch (err) {\n  if (err instanceof Error && err.message === \"--port must be 1..65535\") {\n    console.error(`Bad --port value '${portArg}'; use an integer 1-65535`);\n    process.exitCode = 1;\n    return;\n  }\n  throw err;\n}","preventionTips":["Validate port values in wrapper scripts before passing them to the server","Never build --port from unvalidated env vars or user input without range-checking","Strip whitespace/suffixes from port strings before numeric conversion","Omit --port to use the documented default (4700)"],"tags":["validation","cli-arguments","port-range"],"backgroundTag":"invalid-port-range","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}