jackwener/OpenCLI · error

profile is required

Error message

profile is required

What it means

setDefaultProfile resolves the given profile name to a contextId (via resolveProfileContextId) or normalizes it directly; if both yield an empty value it throws 'profile is required'. A default profile must map to a non-empty contextId.

Source

Thrown at src/browser/profile.ts:123

  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);
  return config;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an existing profile alias or valid contextId to setDefaultProfile
  2. List available profiles first (e.g. loadProfileConfig) to confirm the name
  3. Ensure the scripting variable feeding the argument is set and non-empty

Example fix

// before
setDefaultProfile('');
// after
setDefaultProfile('work'); // existing alias or valid contextId
Defensive patterns

Strategy: validation

Validate before calling

const profiles = loadProfileConfig();
if (!profile || (!profiles.aliases[profile] && !profile.trim())) {
  throw new Error(`unknown or empty profile: ${JSON.stringify(profile)}`);
}

Type guard

function isKnownProfile(p: string, cfg: ProfileConfig): boolean {
  return Boolean(cfg.aliases[p]) || p.trim().length > 0;
}

Try / catch

try { setDefaultProfile(name); }
catch (e) {
  if (e.message === 'profile is required') {
    console.error('Usage: config set-default <profile>');
  } throw e;
}

Prevention

When it happens

Trigger: Calling setDefaultProfile('') or with a profile argument that is neither a known alias nor normalizes to a non-empty contextId (e.g. only whitespace).

Common situations: CLI config command invoked without the profile argument; typo'd profile name not registered as an alias; empty environment variable passed through scripting.

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/a8311171bd68cf33. Report an issue: GitHub.