jackwener/OpenCLI · error
profile contextId is required
Error message
profile contextId is required
What it means
renameProfile normalizes its contextId argument and throws 'profile contextId is required' when the normalized value is empty. Profiles are keyed by a non-empty contextId, so renaming without one is invalid.
Source
Thrown at src/browser/profile.ts:107
? { contextId: selection.contextId }
: { preferredContextId: selection.contextId };
}
export function resolveProfileContextId(profile?: string): string | undefined {
return resolveProfileSelection(profile)?.contextId;
}
export function aliasForContextId(config: ProfileConfig, contextId: string): string | undefined {
for (const [alias, id] of Object.entries(config.aliases)) {
if (id === contextId) return alias;
}
return undefined;
}
export function renameProfile(contextId: string, alias: string): ProfileConfig {
const normalizedContextId = normalizeContextId(contextId);
const normalizedAlias = normalizeContextId(alias);
if (!normalizedContextId) throw new Error('profile contextId is required');
if (!normalizedAlias) throw new Error('profile alias is required');
const config = loadProfileConfig();
for (const [existingAlias, existingContextId] of Object.entries(config.aliases)) {
if (existingAlias !== normalizedAlias && existingContextId === normalizedContextId) {
delete config.aliases[existingAlias];
}
}
config.aliases[normalizedAlias] = normalizedContextId;
saveProfileConfig(config);
return config;
}
export function setDefaultProfile(profile: string): ProfileConfig {
const contextId = resolveProfileContextId(profile) ?? normalizeContextId(profile);
if (!contextId) throw new Error('profile is required');
const config = loadProfileConfig();
config.defaultContextId = contextId;View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a valid non-empty contextId as the first argument
- Check the value for stray whitespace/invalid characters before calling
- Prompt or default the contextId in the CLI when the argument is missing
Example fix
// before
renameProfile('', 'work');
// after
renameProfile('ctx-1234', 'work'); Defensive patterns
Strategy: validation
Validate before calling
if (!contextId || !contextId.trim()) throw new Error('contextId required before renameProfile'); Type guard
function isValidContextId(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try { renameProfile(ctxId, alias); }
catch (e) {
if (e.message === 'profile contextId is required') {
throw new Error(`bad contextId: ${JSON.stringify(ctxId)}`);
} throw e;
} Prevention
- Trim inputs before passing to profile APIs
- Reject empty/whitespace args at CLI parse time
- Check config for undefined values feeding arguments
When it happens
Trigger: Calling renameProfile('', alias) or renameProfile with a contextId that normalizes to empty (whitespace-only or invalid characters stripped by normalizeContextId).
Common situations: CLI invocation missing the contextId argument; passing a value containing only spaces or characters normalizeContextId removes; programmatic use reading an unset config value.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- profile alias is required
- profile is required
- Invalid trace maxAgeDays: ${maxAgeDays}
- Invalid trace maxCountPerProfile: ${maxCountPerProfile}
- TAP_MISSING_PARAMS
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/bead4675585138a5.
Report an issue: GitHub.