{"record":{"id":"73a568925ee2b060","repo":"tinyhumansai/openhuman","slug":"label-must-be-an-integer-between-1-and-65535","errorCode":null,"errorMessage":"${label} must be an integer between 1 and 65535","messagePattern":"(.+?) must be an integer between 1 and 65535","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/mock-api-server.mjs","lineNumber":15,"sourceCode":"#!/usr/bin/env node\nimport process from \"node:process\";\n\nimport { DEFAULT_PORT, startMockServer, stopMockServer } from \"./mock-api-core.mjs\";\n\nfunction usage() {\n  return \"Usage: node scripts/mock-api-server.mjs [--port <port>]\";\n}\n\nfunction parsePortValue(value, label) {\n  const port = Number(value);\n  if (Number.isInteger(port) && port > 0 && port <= 65535) {\n    return port;\n  }\n  throw new Error(`${label} must be an integer between 1 and 65535`);\n}\n\nfunction readPortArg() {\n  const idx = process.argv.findIndex((arg) => arg === \"--port\" || arg === \"-p\");\n  if (idx >= 0) {\n    const value = process.argv[idx + 1];\n    if (!value || value.startsWith(\"-\")) {\n      console.error(\"[mock-api-server] --port requires an integer between 1 and 65535\");\n      process.exit(2);\n    }\n    try {\n      return parsePortValue(value, \"--port\");\n    } catch (err) {\n      console.error(`[mock-api-server] ${err.message}`);\n      process.exit(2);\n    }\n  }\n  if (process.argv.includes(\"--help\") || process.argv.includes(\"-h\")) {","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/a221052e0df5b1f7598fceba7329fd1af95d6699/scripts/mock-api-server.mjs#L1-L33","documentation":"scripts/mock-api-server.mjs validates the --port/-p argument with parsePortValue(): the value must Number()-convert to an integer strictly greater than 0 and at most 65535. Anything else — non-numeric, 0, negative, 70000, NaN — throws and main().catch exits 1. Note the sibling case: a --port value that is missing or itself starts with '-' exits 2 with a different message before this check runs.","triggerScenarios":"`node scripts/mock-api-server.mjs --port 0`, `--port abc`, `--port 70000`, or an unset shell var expanding to empty (`--port $PORT` with PORT empty → Number('') === 0 → invalid).","commonSituations":"CI passing an unconfigured port variable; picking a port outside the ephemeral range; typo'd numeric value.","solutions":["Pass an integer in 1..65535, e.g. `--port 4173`","If the port comes from a variable, default it first: `--port \"${MOCK_PORT:-4173}\"`","Or omit --port entirely — the server falls back to MOCK_API_PORT / E2E_MOCK_PORT env vars and then DEFAULT_PORT, which is always valid"],"exampleFix":"# before\nnode scripts/mock-api-server.mjs --port $PORT   # PORT unset → '' → invalid\n\n# after\nnode scripts/mock-api-server.mjs --port \"${PORT:-4173}\"","handlingStrategy":"validation","validationCode":"function resolvePort(raw) {\n  const n = Number(raw);\n  if (Number.isInteger(n) && n > 0 && n <= 65535) return n;\n  console.error(`Invalid port '${raw}' — falling back to default`);\n  return undefined; // or exit non-zero in strict callers\n}","typeGuard":"/** Narrows to a TCP-port-safe integer in 1..65535. */\nfunction isValidPort(value) {\n  const n = Number(value);\n  return Number.isInteger(n) && n > 0 && n <= 65535;\n}","tryCatchPattern":"try {\n  startMockServer(readPortArg());\n} catch (err) {\n  if (err.message.includes('must be an integer between 1 and 65535')) {\n    console.error('Pass --port <1-65535> or set MOCK_API_PORT; see --help');\n    process.exit(2);\n  }\n  throw err;\n}","preventionTips":["Default expanded variables: `--port \"${PORT:-4173}\"` — an unset var expands to '' which Number()s to 0 and fails","Reuse the mock API's own env fallback (MOCK_API_PORT / E2E_MOCK_PORT) instead of hand-passing ports everywhere"],"tags":["cli","validation","networking","developer-tooling"],"backgroundTag":null,"analyzedSha":"a221052e0df5b1f7598fceba7329fd1af95d6699","analyzedAt":"2026-08-16T12:47:06.542Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}