cube-js/cube · error
context `{name}` not found (run `cube login --name {name}`)
Error message
context `{name}` not found (run `cube login --name {name}`) What it means
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>`.
Source
Thrown at rust/cube-cli/src/commands/context.rs:43
Cmd::List => {
let rows = ctx
.config
.contexts
.iter()
.map(|(name, c)| {
let active = if ctx.config.default_context.as_deref() == Some(name.as_str()) {
"*"
} else {
""
};
vec![active.to_string(), name.clone(), c.url.clone()]
})
.collect();
output::table(&["", "NAME", "URL"], rows);
}
Cmd::Use { name } => {
if !ctx.config.contexts.contains_key(&name) {
bail!("context `{name}` not found (run `cube login --name {name}`)");
}
ctx.config.default_context = Some(name.clone());
ctx.config.save()?;
output::success(&format!("Switched to context `{name}`"));
}
}
Ok(())
}
View on GitHub (pinned to 7d981676b3)
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
Example fix
// before cube context use prod-us # not found // after cube login --name prod-us cube context use prod-us
Defensive patterns
Strategy: validation
Validate before calling
import { execSync } from 'child_process';
const list = execSync('cube context list').toString();
if (!list.includes(name)) { console.error(`Context '${name}' missing — run: cube login --name ${name}`); process.exit(1); } Type guard
function contextExists(config: { contexts: Record<string, unknown> }, name: string): boolean {
return Object.prototype.hasOwnProperty.call(config.contexts, name);
} Try / catch
try {
await exec('cube context use ' + name);
} catch (e) {
if (/not found \(run `cube login/.test(String(e))) { await exec(`cube login --name ${name}`); }
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No app secret found
- API URL is empty
- provide --file <path> or --content <text>
- file not found: {path}
- context `{name}` not found in config (run `cube login --cont
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/cb5d79362354cc73.
Report an issue: GitHub.