{"record":{"id":"bead4675585138a5","repo":"jackwener/OpenCLI","slug":"profile-contextid-is-required","errorCode":null,"errorMessage":"profile contextId is required","messagePattern":"profile contextId is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/browser/profile.ts","lineNumber":107,"sourceCode":"    ? { contextId: selection.contextId }\n    : { 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;","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/browser/profile.ts#L89-L125","documentation":"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.","triggerScenarios":"Calling renameProfile('', alias) or renameProfile with a contextId that normalizes to empty (whitespace-only or invalid characters stripped by normalizeContextId).","commonSituations":"CLI invocation missing the contextId argument; passing a value containing only spaces or characters normalizeContextId removes; programmatic use reading an unset config value.","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"],"exampleFix":"// before\nrenameProfile('', 'work');\n// after\nrenameProfile('ctx-1234', 'work');","handlingStrategy":"validation","validationCode":"if (!contextId || !contextId.trim()) throw new Error('contextId required before renameProfile');","typeGuard":"function isValidContextId(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 contextId is required') {\n    throw new Error(`bad contextId: ${JSON.stringify(ctxId)}`);\n  } throw e;\n}","preventionTips":["Trim inputs before passing to profile APIs","Reject empty/whitespace args at CLI parse time","Check config for undefined values feeding arguments"],"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"}