{"record":{"id":"bf84d3d834a16180","repo":"Mintplex-Labs/anything-llm","slug":"invalid-collector-port-process-env-collector-po","errorCode":null,"errorMessage":"Invalid COLLECTOR_PORT \"${process.env.COLLECTOR_PORT}\". Falling back to ${DEFAULT_COLLECTOR_PORT}.","messagePattern":"Invalid COLLECTOR_PORT \"(.+?)\"\\. Falling back to (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"collector/utils/http/index.js","lineNumber":43,"sourceCode":"    new URL(baseUrl);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Gets the collector port from the environment variables.\n * If the port is not set, it will fall back to the default port.\n * If the port is invalid, it will log a warning and return the default port.\n * @returns {number}\n */\nfunction getCollectorPort() {\n  if (!(\"COLLECTOR_PORT\" in process.env)) return DEFAULT_COLLECTOR_PORT;\n  const port = Number(process.env.COLLECTOR_PORT);\n  if (Number.isInteger(port) && port > 0 && port <= 65535) return port;\n\n  console.warn(\n    `Invalid COLLECTOR_PORT \"${process.env.COLLECTOR_PORT}\". Falling back to ${DEFAULT_COLLECTOR_PORT}.`\n  );\n  return DEFAULT_COLLECTOR_PORT;\n}\n\nmodule.exports = {\n  reqBody,\n  queryParams,\n  validBaseUrl,\n  getCollectorPort,\n};\n","sourceCodeStart":25,"sourceCodeEnd":55,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/collector/utils/http/index.js#L25-L55","documentation":"getCollectorPort found COLLECTOR_PORT in the environment but it did not parse to an integer in 1–65535, so the collector listens on DEFAULT_COLLECTOR_PORT instead. Common culprits: trailing whitespace/quotes, letters, floats, 0, or values above 65535.","triggerScenarios":"COLLECTOR_PORT set to \"0\", \"70000\", \"8888 \" (trailing space), \"tcp://8888\", or copied with quotes from documentation; .env file edited on Windows adding a BOM or CRLF that corrupts parsing.","commonSituations":"Docker-compose/Dockerfile ENV values quoted oddly; Kubernetes ConfigMap values with stray characters; port-forwarding mismatches because the collector is not on the port the operator thinks.","solutions":["Set COLLECTOR_PORT to a plain positive integer between 1 and 65535 (e.g. COLLECTOR_PORT=8888).","Print the variable with delimiters to reveal hidden characters: printf '[%s]' \"$COLLECTOR_PORT\".","Re-save the .env file with LF line endings and no BOM.","Confirm the container/port mapping actually uses the default port, since your configured value is being ignored."],"exampleFix":"# before\nCOLLECTOR_PORT=\"8888 \"\n\n# after\nCOLLECTOR_PORT=8888","handlingStrategy":"validation","validationCode":"// Fail fast at container start instead of silently using the default:\nconst raw = process.env.COLLECTOR_PORT;\nif (raw != null) {\n  const port = Number(raw);\n  if (!Number.isInteger(port) || port < 1 || port > 65535) {\n    throw new Error(`COLLECTOR_PORT=\"${raw}\" is invalid — expected integer 1-65535`);\n  }\n}","typeGuard":"function isValidPort(value) {\n  const n = Number(value);\n  return Number.isInteger(n) && n > 0 && n <= 65535;\n}","tryCatchPattern":null,"preventionTips":["Lint .env files for numeric variables in CI.","Save env files with LF endings and no BOM.","Echo variables with delimiters during deployment debugging to spot hidden characters.","Align container port mappings with the port the collector actually logs at startup."],"tags":["env-var","port","configuration","collector"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}