cube-js/cube · error · UserError
Context ${contextId} doesn't exist
Error message
Context ${contextId} doesn't exist What it means
queriesForContext looks up a pre-defined (multitenant) context definition by id in contextDefinitions. If the id is unknown, it throws this UserError instead of returning an empty list, so misconfiguration fails loudly. Contexts are defined via contextToConfigs / context definitions and map queries to cubes per context.
Source
Thrown at packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.ts:388
name: `${cubeName}.${it.name}`,
})),
folders: flatFolders,
nestedFolders,
},
};
}
public queriesForContext(contextId: string | null | undefined): TransformedCube[] {
// return All queries if no context pass
if (contextId == null || contextId.length === 0) {
return this.queries;
}
const context = (this.contextEvaluator as any).contextDefinitions[contextId];
// If contextId is wrong
if (context == null) {
throw new UserError(`Context ${contextId} doesn't exist`);
}
// As for now context works on the cubes level
return this.queries.filter(
(query) => context.contextMembers.includes(query.config.name)
);
}
/**
* @protected
*/
protected isVisible(symbol: any, defaultValue: boolean): boolean {
if (symbol.public != null) {
return symbol.public;
}
// TODO: Deprecated, should be removed in the future
if (symbol.visible != null) {View on GitHub (pinned to 7d981676b3)
Solutions
- Check the context id against the keys defined in your contexts configuration (log Object.keys(contextDefinitions)).
- Fix the renamed/typoed id in the calling code.
- Ensure the config defining contexts is actually passed to DataSchemaCompiler before calling queriesForContext.
- Guard calls: only invoke for ids present in the compiled context list.
Example fix
// before
const queries = compiler.queriesForContext('tenant-a');
// after
const contexts = (compiler.contextEvaluator as any).contextDefinitions;
if (!(contextId in contexts)) throw new Error(`Unknown context: ${contextId}`);
const queries = compiler.queriesForContext(contextId); Defensive patterns
Strategy: validation
Validate before calling
const defs = (compiler.contextEvaluator as any).contextDefinitions || {};
if (!(contextId in defs)) {
throw new Error(`Unknown context id: ${contextId}. Available: ${Object.keys(defs).join(', ')}`);
} Type guard
function contextExists(compiler, id) { return id in ((compiler.contextEvaluator as any)?.contextDefinitions || {}); } Try / catch
try { const qs = compiler.queriesForContext(id); } catch (e) { if (/doesn't exist/.test(e.message)) { console.error('Fix context id or contexts config'); } throw e; } Prevention
- Centralize context id constants to avoid typos
- Log available context ids when wiring multitenant compilation
- Ensure contexts config is loaded before querying contexts
When it happens
Trigger: Calling `compiler.queriesForContext('someContextId')` where the id was never registered, was renamed, or the config defining contexts wasn't passed to the compiler (so contextDefinitions is empty).
Common situations: Typo in the context id when generating schema per context in multitenant deployments; contexts renamed in config but the calling code still uses old ids; orchestration code calling queriesForContext before contexts are compiled.
Related errors
- COMPILE_CONTEXT can't be used unless contextToAppId is defin
- A user-defined contextToApiScopes function returns an incons
- A user-defined contextToApiScopes function returns a wrong s
- Unload is not configured. Please define CUBEJS_AWS_S3_OUTPUT
- Export bucket is not configured.
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/c7d9ec90f4cc4a24.
Report an issue: GitHub.