{"record":{"id":"7869255edd0e96e3","repo":"cube-js/cube","slug":"value-input-is-not-valid-for-envname-shou","errorCode":null,"errorMessage":"Value \"${input}\" is not valid for ${envName}. Should be a positive integer.","messagePattern":"Value \"(.+?)\" is not valid for (.+?)\\. Should be a positive integer\\.","errorType":"validation","errorClass":"InvalidConfiguration","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/env.ts","lineNumber":65,"sourceCode":"    switch (input.slice(-2).toLowerCase()) {\n      case 'kb':\n        return parseInt(input.slice(0, -2), 10) * 1024;\n      case 'mb':\n        return parseInt(input.slice(0, -2), 10) * 1024 * 1024;\n      case 'gb':\n        return parseInt(input.slice(0, -2), 10) * 1024 * 1024 * 1024;\n      default: {\n        throw new InvalidConfiguration(envName, input, description);\n      }\n    }\n  }\n\n  throw new InvalidConfiguration(envName, input, description);\n}\n\nexport function asPortNumber(input: number, envName: string) {\n  if (input < 0) {\n    throw new InvalidConfiguration(envName, input, 'Should be a positive integer.');\n  }\n\n  if (input > 65535) {\n    throw new InvalidConfiguration(envName, input, 'Should be lower or equal than 65535.');\n  }\n\n  return input;\n}\n\n/**\n * Determines whether multiple data sources were declared or not.\n */\nfunction isMultipleDataSources(): boolean {\n  // eslint-disable-next-line no-use-before-define\n  return getEnv('dataSources').length > 0;\n}\n\n/**","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/env.ts#L47-L83","documentation":"asPortNumber validates port-typed env variables and throws InvalidConfiguration when the value is negative. The message says 'Should be a positive integer.' Port numbers must be 0-65535, so Cube rejects out-of-range values at startup rather than binding a nonsensical port. Callers include asPortOrSocket and asFalseOrPort.","triggerScenarios":"Setting a port env var (e.g. CUBEJS_PORT or CUBEJS_SQL_PORT) to a negative number like -1 or -8080, or to a value that resolves to a negative number.","commonSituations":"Sign/typo mistakes in .env files; templated configs where a placeholder was replaced with a negative or malformed value; disabling a port by trying a negative value instead of the documented sentinel (e.g. false).","solutions":["Set the env var to an integer between 0 and 65535 (e.g. 4000).","If you meant to disable the port-based feature, use the documented alternative (e.g. CUBEJS_SQL_PORT=false via asFalseOrPort) instead of a negative number.","Check for stray minus signs or corrupted values in the .env file."],"exampleFix":"// before (.env)\nCUBEJS_PORT=-4000\n\n// after (.env)\nCUBEJS_PORT=4000","handlingStrategy":"validation","validationCode":"const raw = Number(process.env.CUBEJS_PORT);\nif (process.env.CUBEJS_PORT !== undefined && !(Number.isInteger(raw) && raw >= 0 && raw <= 65535)) {\n  throw new Error(`CUBEJS_PORT=\"${process.env.CUBEJS_PORT}\" must be an integer 0-65535.`);\n}","typeGuard":"function isValidPort(v: unknown): v is number {\n  return typeof v === 'number' && Number.isInteger(v) && v >= 0 && v <= 65535;\n}","tryCatchPattern":"try {\n  startCubeServer();\n} catch (e) {\n  if (e instanceof InvalidConfiguration && e.message.includes('Should be a positive integer')) {\n    console.error('Port env var must be >= 0; to disable the feature use the documented false sentinel.');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Never use negative values for port env vars.","Use the documented sentinel (e.g. false) to disable a port-based feature, not -1.","Range-check ports 0-65535 in your config validation script.","Watch for templating mistakes that inject negative or placeholder values."],"tags":["configuration","env-var","port","validation"],"backgroundTag":"invalid-env-value","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}