cube-js/cube · error · Error
The ${origin} environment variable can not be converted for
Error message
The ${origin} environment variable can not be converted for the ${dataSource} data source. What it means
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.
Source
Thrown at packages/cubejs-backend-shared/src/env.ts:118
}
}
/**
* Returns data source specific environment variable name.
*/
export function keyByDataSource(origin: string, dataSource?: string, preAggregations?: boolean): string {
if (dataSource) assertDataSource(dataSource);
let key: string;
if (!isMultipleDataSources() || dataSource === 'default' || !dataSource) {
key = origin;
} else {
const s = origin.split('CUBEJS_');
if (s.length === 2) {
key = `CUBEJS_DS_${dataSource.toUpperCase()}_${s[1]}`;
} else {
throw new Error(
`The ${
origin
} environment variable can not be converted for the ${
dataSource
} data source.`
);
}
}
if (preAggregations) {
const dsMatch = key.match(/^(CUBEJS_DS_[A-Z0-9_]+?_)(DB_|JDBC_|AWS_|DATABASE|FIREBOLT_)(.*)/);
if (dsMatch) {
return `${dsMatch[1]}PRE_AGGREGATIONS_${dsMatch[2]}${dsMatch[3]}`;
}
if (key.startsWith('CUBEJS_')) {
return key.replace(/^CUBEJS_/, 'CUBEJS_PRE_AGGREGATIONS_');
}View on GitHub (pinned to 7d981676b3)
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.
Example fix
// before
const key = keyByDataSource('CUBEJS_DS_MYSQL_DB_USER', 'mysql'); // throws
// after
const key = keyByDataSource('CUBEJS_DB_USER', 'mysql'); // -> CUBEJS_DS_MYSQL_DB_USER Defensive patterns
Strategy: validation
Validate before calling
function isConvertibleEnvName(name) {
return typeof name === 'string' && name.split('CUBEJS_').length === 2;
}
if (!isConvertibleEnvName('CUBEJS_DB_USER')) throw new Error('name must contain exactly one CUBEJS_ prefix'); Type guard
function isConvertibleEnvName(name: unknown): name is `CUBEJS_${string}` {
return typeof name === 'string' && /^CUBEJS_(?!.*CUBEJS_).+/.test(name);
} Try / catch
try {
const key = keyByDataSource(name, dataSource);
} catch (e) {
console.error(`Cannot derive DS-specific var for ${name}: ${e.message}`);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Value "${value}" is not valid for CUBEJS_MAX_REQUEST_SIZE. M
- The ${keyByDataSource('CUBEJS_DB_SSL', dataSource)} must be
- The ${keyByDataSource('CUBEJS_DB_SSL_REJECT_UNAUTHORIZED', d
- The ${keyByDataSource('CUBEJS_DB_USE_SELECT_TEST_CONNECTION'
- The ${keyByDataSource('CUBEJS_DB_NAME', dataSource)} is requ
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/2c6e6f533bdd3936.
Report an issue: GitHub.