jackwener/OpenCLI · error

profile alias is required

Error message

profile alias is required

What it means

renameProfile normalizes the alias and throws 'profile alias is required' when it normalizes to empty. The new alias must be a non-empty normalized identifier for the rename to proceed.

Source

Thrown at src/browser/profile.ts:108

    : { 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;
  saveProfileConfig(config);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Provide a valid non-empty alias as the second argument
  2. Validate/sanitize the alias string before calling
  3. Fix the CLI invocation so both contextId and alias are supplied

Example fix

// before
renameProfile('ctx-1234', process.env.ALIAS); // ALIAS unset → ''
// after
const alias = process.env.ALIAS;
if (alias) renameProfile('ctx-1234', alias);
Defensive patterns

Strategy: validation

Validate before calling

if (!alias || !alias.trim()) throw new Error('alias required before renameProfile');

Type guard

function isValidAlias(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 alias is required') {
    throw new Error(`bad alias: ${JSON.stringify(alias)}`);
  } throw e;
}

Prevention

When it happens

Trigger: Calling renameProfile(contextId, '') or with an alias that normalizeContextId reduces to an empty string (whitespace-only or stripped characters).

Common situations: CLI invocation like `opencli profile rename ctx-1234` missing the alias argument; alias containing only spaces; scripting that forwards an unset shell variable as the alias.

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/96246bb9efb196ad. Report an issue: GitHub.