{"record":{"id":"2c6e6f533bdd3936","repo":"cube-js/cube","slug":"the-origin-environment-variable-can-not-be-conv","errorCode":null,"errorMessage":"The ${origin} environment variable can not be converted for the ${dataSource} data source.","messagePattern":"The (.+?) environment variable can not be converted for the (.+?) data source\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-shared/src/env.ts","lineNumber":118,"sourceCode":"  }\n}\n\n/**\n * Returns data source specific environment variable name.\n */\nexport function keyByDataSource(origin: string, dataSource?: string, preAggregations?: boolean): string {\n  if (dataSource) assertDataSource(dataSource);\n\n  let key: string;\n\n  if (!isMultipleDataSources() || dataSource === 'default' || !dataSource) {\n    key = origin;\n  } else {\n    const s = origin.split('CUBEJS_');\n    if (s.length === 2) {\n      key = `CUBEJS_DS_${dataSource.toUpperCase()}_${s[1]}`;\n    } else {\n      throw new Error(\n        `The ${\n          origin\n        } environment variable can not be converted for the ${\n          dataSource\n        } data source.`\n      );\n    }\n  }\n\n  if (preAggregations) {\n    const dsMatch = key.match(/^(CUBEJS_DS_[A-Z0-9_]+?_)(DB_|JDBC_|AWS_|DATABASE|FIREBOLT_)(.*)/);\n    if (dsMatch) {\n      return `${dsMatch[1]}PRE_AGGREGATIONS_${dsMatch[2]}${dsMatch[3]}`;\n    }\n\n    if (key.startsWith('CUBEJS_')) {\n      return key.replace(/^CUBEJS_/, 'CUBEJS_PRE_AGGREGATIONS_');\n    }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-shared/src/env.ts#L100-L136","documentation":"keyByDataSource converts a generic CUBEJS_* environment variable name into a per-data-source name like CUBEJS_DS_<DS>_<SUFFIX> by splitting on 'CUBEJS_'. Cube throws this error when the variable name does not contain exactly one 'CUBEJS_' prefix (the split yields more than 2 parts), so it cannot be mechanically rewritten for the requested data source.","triggerScenarios":"Calling any env-flags accessor (variables, val, key, value, credentials, extensions) with a dataSource while the underlying variable name contains 'CUBEJS_' twice — e.g. an already data-source-scoped name like CUBEJS_DS_PG_CUBEJS_API_SECRET, or a malformed variable CUBEJS_CUBEJS_X — or keyByDataSource being handed a non-CUBEJS_ name that still contains an extra 'CUBEJS_' substring.","commonSituations":"Developers manually setting both generic and DS-prefixed env vars and passing the prefixed one into helpers; typos producing CUBEJS_CUBEJS_...; calling internal keyByDataSource directly with an already-converted key; custom driver code re-invoking keyByDataSource on output of a previous call.","solutions":["Pass the generic variable name (e.g. 'CUBEJS_API_SECRET'), not one that already contains a CUBEJS_DS_ prefix, to keyByDataSource.","Check the offending env var name for duplicated CUBEJS_/CUBEJS_DS_ prefixes and fix the typo in your environment configuration.","If you need a data-source-specific value, set CUBEJS_DS_<DATASOURCE>_<SUFFIX> directly in the environment instead of converting a converted name.","For custom integrations, ensure dataSource is a valid non-empty string so toUpperCase produces the expected key."],"exampleFix":"// before\nconst key = keyByDataSource('CUBEJS_DS_MYSQL_DB_USER', 'mysql'); // throws\n// after\nconst key = keyByDataSource('CUBEJS_DB_USER', 'mysql'); // -> CUBEJS_DS_MYSQL_DB_USER","handlingStrategy":"validation","validationCode":"function isConvertibleEnvName(name) {\n  return typeof name === 'string' && name.split('CUBEJS_').length === 2;\n}\nif (!isConvertibleEnvName('CUBEJS_DB_USER')) throw new Error('name must contain exactly one CUBEJS_ prefix');","typeGuard":"function isConvertibleEnvName(name: unknown): name is `CUBEJS_${string}` {\n  return typeof name === 'string' && /^CUBEJS_(?!.*CUBEJS_).+/.test(name);\n}","tryCatchPattern":"try {\n  const key = keyByDataSource(name, dataSource);\n} catch (e) {\n  console.error(`Cannot derive DS-specific var for ${name}: ${e.message}`);\n}","preventionTips":["Only pass generic CUBEJS_* names to keyByDataSource, never CUBEJS_DS_* output.","Set data-source-specific values directly as CUBEJS_DS_<DS>_<SUFFIX> env vars.","Lint env files for duplicated CUBEJS_ prefixes."],"tags":["environment-variables","configuration","data-source"],"backgroundTag":"invalid-env-var-name","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}