{"record":{"id":"733c57c4ed1a0af9","repo":"paperclipai/paperclip","slug":"invalid-port-raw-733c57","errorCode":null,"errorMessage":"Invalid port: ${raw}","messagePattern":"Invalid port: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/kv-demo-mcp-server/src/config.ts","lineNumber":18,"sourceCode":"export interface KvDemoConfig {\n  port: number;\n  host: string;\n  /** Optional shared secret. When set, all routes require it. */\n  token: string | null;\n}\n\nexport interface KvDemoConfigInput {\n  port?: string | number | null;\n  host?: string | null;\n  token?: string | null;\n}\n\nfunction parsePort(raw: string | number | null | undefined): number {\n  if (raw === null || raw === undefined || raw === \"\") return 8848;\n  const port = typeof raw === \"number\" ? raw : Number.parseInt(raw, 10);\n  if (!Number.isInteger(port) || port < 0 || port > 65535) {\n    throw new Error(`Invalid port: ${raw}`);\n  }\n  return port;\n}\n\nexport function createKvDemoConfig(input: KvDemoConfigInput): KvDemoConfig {\n  const token = input.token?.trim();\n  return {\n    port: parsePort(input.port),\n    host: input.host?.trim() || \"127.0.0.1\",\n    token: token ? token : null,\n  };\n}\n\nexport function readConfigFromEnv(env: NodeJS.ProcessEnv = process.env): KvDemoConfig {\n  return createKvDemoConfig({\n    port: env.PORT ?? env.KV_DEMO_PORT,\n    host: env.KV_DEMO_HOST,\n    token: env.KV_DEMO_TOKEN,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/packages/kv-demo-mcp-server/src/config.ts#L1-L36","documentation":"parsePort in the kv-demo MCP server config accepts string or number and requires the result to be an integer in [0, 65535]; anything else throws. An empty/null/undefined value is allowed and defaults to 8848, so the error only fires on a present-but-invalid value.","triggerScenarios":"KvDemoConfigInput.port is a non-numeric string ('abc'), a float (8848.5), a number outside 0–65535 (70000, -1), or a string with garbage ('8848/tcp'). Number.parseInt on a float string like '8080' works, but '80.5' yields 80 — note partial parse quirks.","commonSituations":"KV_PORT env var set to a value with a unit suffix, a quoted float, or a port duplicated by mistake (80808080); mis-typed config in a YAML/JSON file read as a string.","solutions":["Set the port to an integer between 0 and 65535 (e.g. KV_PORT=8848).","Unset the port variable to fall back to the default 8848.","Strip any non-digit characters from the configured value before passing it in."],"exampleFix":"// before\ncreateKvDemoConfig({ port: '8848/tcp' })  // -> Invalid port: 8848/tcp\n// after\ncreateKvDemoConfig({ port: 8848 })","handlingStrategy":"validation","validationCode":"function validPort(raw: string|number|null|undefined): boolean {\n  if (raw === null || raw === undefined || raw === '') return true;\n  const n = typeof raw === 'number' ? raw : Number.parseInt(String(raw), 10);\n  return Number.isInteger(n) && n >= 0 && n <= 65535 && String(raw).match(/^[0-9]+$/) !== null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass ports as plain integers, not strings with units.","Unset the port var to accept the 8848 default rather than risk an invalid literal.","Validate config in your launcher before the server reads it."],"tags":["configuration","validation","port","kv-demo-mcp"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}