{"record":{"id":"96246bb9efb196ad","repo":"jackwener/OpenCLI","slug":"profile-alias-is-required","errorCode":null,"errorMessage":"profile alias is required","messagePattern":"profile alias is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/browser/profile.ts","lineNumber":108,"sourceCode":"    : { preferredContextId: selection.contextId };\n}\n\nexport function resolveProfileContextId(profile?: string): string | undefined {\n  return resolveProfileSelection(profile)?.contextId;\n}\n\nexport function aliasForContextId(config: ProfileConfig, contextId: string): string | undefined {\n  for (const [alias, id] of Object.entries(config.aliases)) {\n    if (id === contextId) return alias;\n  }\n  return undefined;\n}\n\nexport function renameProfile(contextId: string, alias: string): ProfileConfig {\n  const normalizedContextId = normalizeContextId(contextId);\n  const normalizedAlias = normalizeContextId(alias);\n  if (!normalizedContextId) throw new Error('profile contextId is required');\n  if (!normalizedAlias) throw new Error('profile alias is required');\n\n  const config = loadProfileConfig();\n  for (const [existingAlias, existingContextId] of Object.entries(config.aliases)) {\n    if (existingAlias !== normalizedAlias && existingContextId === normalizedContextId) {\n      delete config.aliases[existingAlias];\n    }\n  }\n  config.aliases[normalizedAlias] = normalizedContextId;\n  saveProfileConfig(config);\n  return config;\n}\n\nexport function setDefaultProfile(profile: string): ProfileConfig {\n  const contextId = resolveProfileContextId(profile) ?? normalizeContextId(profile);\n  if (!contextId) throw new Error('profile is required');\n  const config = loadProfileConfig();\n  config.defaultContextId = contextId;\n  saveProfileConfig(config);","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/browser/profile.ts#L90-L126","documentation":"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.","triggerScenarios":"Calling renameProfile(contextId, '') or with an alias that normalizeContextId reduces to an empty string (whitespace-only or stripped characters).","commonSituations":"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.","solutions":["Provide a valid non-empty alias as the second argument","Validate/sanitize the alias string before calling","Fix the CLI invocation so both contextId and alias are supplied"],"exampleFix":"// before\nrenameProfile('ctx-1234', process.env.ALIAS); // ALIAS unset → ''\n// after\nconst alias = process.env.ALIAS;\nif (alias) renameProfile('ctx-1234', alias);","handlingStrategy":"validation","validationCode":"if (!alias || !alias.trim()) throw new Error('alias required before renameProfile');","typeGuard":"function isValidAlias(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try { renameProfile(ctxId, alias); }\ncatch (e) {\n  if (e.message === 'profile alias is required') {\n    throw new Error(`bad alias: ${JSON.stringify(alias)}`);\n  } throw e;\n}","preventionTips":["Require both arguments in CLI wrappers","Validate env-sourced aliases are set","Sanitize whitespace-only input"],"tags":["configuration","validation","profiles"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}