{"record":{"id":"fb80b4248606ac4f","repo":"different-ai/openwork","slug":"port-must-be-an-integer-between-1-and-65535","errorCode":null,"errorMessage":"PORT must be an integer between 1 and 65535","messagePattern":"PORT must be an integer between 1 and 65535","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-gateway/src/env.ts","lineNumber":31,"sourceCode":"  DEN_GATEWAY_LOG_REQUESTS: z.string().optional(),\n})\n\nconst parsed = EnvSchema.parse(process.env)\n\nfunction optionalString(value: string | undefined) {\n  const trimmed = value?.trim()\n  return trimmed ? trimmed : undefined\n}\n\n// GH Actions builds pass DEN_GATEWAY_VERSION; Render repo builds rely on RENDER_GIT_COMMIT.\nexport function resolveGatewayBuildVersion(input: { denGatewayVersion?: string; renderGitCommit?: string }): string | undefined {\n  return optionalString(input.denGatewayVersion) ?? optionalString(input.renderGitCommit)\n}\n\nfunction parsePort(value: string | undefined) {\n  const port = Number(value ?? \"8788\")\n  if (!Number.isInteger(port) || port <= 0 || port > 65535) {\n    throw new Error(\"PORT must be an integer between 1 and 65535\")\n  }\n  return port\n}\n\nfunction parsePositiveInteger(envName: string, value: string | undefined, fallback: number) {\n  const parsedValue = Number(value ?? String(fallback))\n  if (!Number.isInteger(parsedValue) || parsedValue <= 0) {\n    throw new Error(`${envName} must be a positive integer`)\n  }\n  return parsedValue\n}\n\nfunction normalizeHttpBaseUrl(envName: string, value: string) {\n  let url: URL\n  try {\n    url = new URL(value)\n  } catch {\n    throw new Error(`${envName} must be an absolute http or https URL`)","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-gateway/src/env.ts#L13-L49","documentation":"The Den gateway validates the PORT environment variable at startup via parsePort: it defaults to 8788, but any provided value that is not an integer in 1..65535 (Number() applied to the raw string) throws 'PORT must be an integer between 1 and 65535', crashing the process during env parsing.","triggerScenarios":"Setting PORT to a non-numeric string ('abc', ''), a quoted value with whitespace/symbols ('\"3000\"'), a float ('3000.5'), 0, a negative number, or a value above 65535 before starting den-gateway.","commonSituations":"Copy-pasting a port from a .env template including quotes; platforms injecting PORT like 'tcp://10.0.0.1:8080' (Docker-style URL, which Number() turns into NaN); typos such as '8788 '; compose files passing ${PORT:-} that expands empty.","solutions":["Set PORT to a plain integer string between 1 and 65535 (e.g. PORT=8788)","Check where the value originates — platform-injected values like 'tcp://host:port' must be parsed down to the numeric port","Unset PORT to fall back to the default 8788","Validate your .env / deployment config for quotes, whitespace, or empty expansions"],"exampleFix":"// before (.env)\nPORT=\"tcp://10.0.0.1:8080\"\n// after (.env)\nPORT=8080","handlingStrategy":"validation","validationCode":"function portIsValid(v) {\n  if (v === undefined || v === '') return true // falls back to 8788\n  const n = Number(v)\n  return Number.isInteger(n) && n > 0 && n <= 65535\n}\nif (!portIsValid(process.env.PORT)) throw new Error(`Invalid PORT: ${process.env.PORT}`)","typeGuard":"function isPortValue(v: unknown): v is `${number}` {\n  const n = Number(v)\n  return typeof v === 'string' && v.trim() !== '' && Number.isInteger(n) && n > 0 && n <= 65535\n}","tryCatchPattern":"try {\n  await import('./env.js') // or start the gateway\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('PORT must be an integer')) {\n    console.error(`Fix PORT in the environment (got \"${process.env.PORT}\"); default is 8788`)\n    process.exit(1)\n  }\n  throw err\n}","preventionTips":["Set PORT as a bare integer with no quotes or whitespace in .env files","Strip Docker-style 'tcp://host:port' injections down to the numeric port before export","Fail fast in CI by importing the env module in a smoke test","Document the default (8788) so empty values are simply unset instead of passed as ''"],"tags":["configuration","env","startup","port"],"backgroundTag":"missing-env-var","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}