{"record":{"id":"45504664777d6742","repo":"cube-js/cube","slug":"context-name-not-found-in-config-run-cube-lo","errorCode":null,"errorMessage":"context `{name}` not found in config (run `cube login --context {name}`)","messagePattern":"context `(.+?)` not found in config \\(run `cube login --context (.+?)`\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cube-cli/src/main.rs","lineNumber":70,"sourceCode":"}\n\nimpl Ctx {\n    fn new(global: &GlobalArgs) -> Result<Self> {\n        Ok(Self {\n            json: global.json,\n            config: config::Config::load()?,\n            api_url: global.api_url.clone(),\n            token: global.token.clone(),\n            context: global.context.clone(),\n        })\n    }\n\n    /// Build an authenticated API client from flags, env, or the config file.\n    pub fn api(&self) -> Result<client::Client> {\n        let ctx = self.config.context(self.context.as_deref());\n        if let Some(name) = &self.context {\n            if ctx.is_none() {\n                bail!(\"context `{name}` not found in config (run `cube login --context {name}`)\");\n            }\n        }\n        let url = self\n            .api_url\n            .clone()\n            .or_else(|| ctx.map(|(_, c)| c.url.clone()))\n            .map(|u| util::normalize_url(&u));\n        // An explicit --token / CUBE_API_KEY wins and disables auto-refresh\n        // (it isn't tied to a stored refresh token).\n        let token = self\n            .token\n            .clone()\n            .or_else(|| ctx.map(|(_, c)| c.api_key.clone()));\n        match (url, token) {\n            (Some(url), Some(token)) => {\n                // Enable auto-refresh only when using the context's own access\n                // token and it has a refresh token saved alongside it.\n                let refresh = if self.token.is_none() {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cube-cli/src/main.rs#L52-L88","documentation":"The CLI resolves authentication from a named context in its config file. When the user explicitly passes --context <name> (or CUBE_CONTEXT) but no context with that name exists in the config, `api()` bails with this message suggesting `cube login --context <name>` to create it.","triggerScenarios":"Running any command with --context production when `cube login --context production` was never run; typos in the context name; switching machines without copying the CLI config; CI environments missing the config file.","commonSituations":"Multiple environments (staging/prod) managed via contexts; fresh laptop setup; sharing scripts that hard-code a context name.","solutions":["Run `cube login --context <name>` to create and authenticate the context","Check the exact context name in the CLI config file (~/.cube/config or equivalent)","Fix the --context flag value or the CUBE_CONTEXT env var typo"],"exampleFix":"// before\ncube deployments list --context prodction\n// after\ncube login --context production\ncube deployments list --context production","handlingStrategy":"validation","validationCode":"const ctx = process.env.CUBE_CONTEXT || flags.context;\nconst cfg = JSON.parse(fs.readFileSync(configPath, \"utf8\"));\nif (ctx && !(ctx in (cfg.contexts ?? {}))) {\n  throw new Error(`context '${ctx}' missing; run: cube login --context ${ctx}`);\n}","typeGuard":"const hasContext = (c: unknown): c is { contexts: Record<string, unknown> } =>\n  typeof c === \"object\" && c !== null && \"contexts\" in c;","tryCatchPattern":"try {\n  run(`cube deployments list --context ${ctx}`);\n} catch (e) {\n  if (String(e).includes(\"not found in config\")) {\n    run(`cube login --context ${ctx}`);\n    run(`cube deployments list --context ${ctx}`);\n  } else throw e;\n}","preventionTips":["Log into every named context after installing the CLI on a new machine","Mount/copy the CLI config file into CI containers","Use consistent context names documented for the team"],"tags":["cli","config","context","authentication"],"backgroundTag":"missing-config-context","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}