{"record":{"id":"c7d9ec90f4cc4a24","repo":"cube-js/cube","slug":"context-contextid-doesn-t-exist","errorCode":null,"errorMessage":"Context ${contextId} doesn't exist","messagePattern":"Context (.+?) doesn't exist","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.ts","lineNumber":388,"sourceCode":"          name: `${cubeName}.${it.name}`,\n        })),\n        folders: flatFolders,\n        nestedFolders,\n      },\n    };\n  }\n\n  public queriesForContext(contextId: string | null | undefined): TransformedCube[] {\n    // return All queries if no context pass\n    if (contextId == null || contextId.length === 0) {\n      return this.queries;\n    }\n\n    const context = (this.contextEvaluator as any).contextDefinitions[contextId];\n\n    // If contextId is wrong\n    if (context == null) {\n      throw new UserError(`Context ${contextId} doesn't exist`);\n    }\n\n    // As for now context works on the cubes level\n    return this.queries.filter(\n      (query) => context.contextMembers.includes(query.config.name)\n    );\n  }\n\n  /**\n   * @protected\n   */\n  protected isVisible(symbol: any, defaultValue: boolean): boolean {\n    if (symbol.public != null) {\n      return symbol.public;\n    }\n\n    // TODO: Deprecated, should be removed in the future\n    if (symbol.visible != null) {","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.ts#L370-L406","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst queries = compiler.queriesForContext('tenant-a');\n// after\nconst contexts = (compiler.contextEvaluator as any).contextDefinitions;\nif (!(contextId in contexts)) throw new Error(`Unknown context: ${contextId}`);\nconst queries = compiler.queriesForContext(contextId);","handlingStrategy":"validation","validationCode":"const defs = (compiler.contextEvaluator as any).contextDefinitions || {};\nif (!(contextId in defs)) {\n  throw new Error(`Unknown context id: ${contextId}. Available: ${Object.keys(defs).join(', ')}`);\n}","typeGuard":"function contextExists(compiler, id) { return id in ((compiler.contextEvaluator as any)?.contextDefinitions || {}); }","tryCatchPattern":"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; }","preventionTips":["Centralize context id constants to avoid typos","Log available context ids when wiring multitenant compilation","Ensure contexts config is loaded before querying contexts"],"tags":["schema-compiler","multitenancy","configuration"],"backgroundTag":"unknown-context-id","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}