{"record":{"id":"cb5d79362354cc73","repo":"cube-js/cube","slug":"context-name-not-found-run-cube-login-name","errorCode":null,"errorMessage":"context `{name}` not found (run `cube login --name {name}`)","messagePattern":"context `(.+?)` not found \\(run `cube login --name (.+?)`\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rust/cube-cli/src/commands/context.rs","lineNumber":43,"sourceCode":"        Cmd::List => {\n            let rows = ctx\n                .config\n                .contexts\n                .iter()\n                .map(|(name, c)| {\n                    let active = if ctx.config.default_context.as_deref() == Some(name.as_str()) {\n                        \"*\"\n                    } else {\n                        \"\"\n                    };\n                    vec![active.to_string(), name.clone(), c.url.clone()]\n                })\n                .collect();\n            output::table(&[\"\", \"NAME\", \"URL\"], rows);\n        }\n        Cmd::Use { name } => {\n            if !ctx.config.contexts.contains_key(&name) {\n                bail!(\"context `{name}` not found (run `cube login --name {name}`)\");\n            }\n            ctx.config.default_context = Some(name.clone());\n            ctx.config.save()?;\n            output::success(&format!(\"Switched to context `{name}`\"));\n        }\n    }\n    Ok(())\n}\n","sourceCodeStart":25,"sourceCodeEnd":52,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cube-cli/src/commands/context.rs#L25-L52","documentation":"The `cube context use <name>` command looks up the named context in the saved CLI config. If the name is absent, it fails with this message, hinting the user to create the context first via `cube login --name <name>`.","triggerScenarios":"Running `cube context use <name>` where <name> is not a key in config.contexts — typo in the name, context never created, or config file on a different machine/profile.","commonSituations":"Switching contexts after reinstalling the CLI or on a new machine; typos in context names; team members using context names that only exist in a colleague's config.","solutions":["Create the context first: `cube login --name <name>`","List existing contexts (`cube context list`) and use one of the listed names","Check the config file path used by the CLI to confirm which config you are editing","Fix the spelling of the context name"],"exampleFix":"// before\ncube context use prod-us  # not found\n// after\ncube login --name prod-us\ncube context use prod-us","handlingStrategy":"validation","validationCode":"import { execSync } from 'child_process';\nconst list = execSync('cube context list').toString();\nif (!list.includes(name)) { console.error(`Context '${name}' missing — run: cube login --name ${name}`); process.exit(1); }","typeGuard":"function contextExists(config: { contexts: Record<string, unknown> }, name: string): boolean {\n  return Object.prototype.hasOwnProperty.call(config.contexts, name);\n}","tryCatchPattern":"try {\n  await exec('cube context use ' + name);\n} catch (e) {\n  if (/not found \\(run `cube login/.test(String(e))) { await exec(`cube login --name ${name}`); }\n  else throw e;\n}","preventionTips":["Run `cube context list` to confirm names before switching","Script logins for every environment used by CI","Use one consistent config file path across machines","Guard against typos with shell completion or exact-match checks"],"tags":["cli","configuration","context","user-input"],"backgroundTag":"context-not-found","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}