{"record":{"id":"a8311171bd68cf33","repo":"jackwener/OpenCLI","slug":"profile-is-required","errorCode":null,"errorMessage":"profile is required","messagePattern":"profile is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/browser/profile.ts","lineNumber":123,"sourceCode":"  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);\n  return config;\n}\n","sourceCodeStart":105,"sourceCodeEnd":129,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/browser/profile.ts#L105-L129","documentation":"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.","triggerScenarios":"Calling setDefaultProfile('') or with a profile argument that is neither a known alias nor normalizes to a non-empty contextId (e.g. only whitespace).","commonSituations":"CLI config command invoked without the profile argument; typo'd profile name not registered as an alias; empty environment variable passed through scripting.","solutions":["Pass an existing profile alias or valid contextId to setDefaultProfile","List available profiles first (e.g. loadProfileConfig) to confirm the name","Ensure the scripting variable feeding the argument is set and non-empty"],"exampleFix":"// before\nsetDefaultProfile('');\n// after\nsetDefaultProfile('work'); // existing alias or valid contextId","handlingStrategy":"validation","validationCode":"const profiles = loadProfileConfig();\nif (!profile || (!profiles.aliases[profile] && !profile.trim())) {\n  throw new Error(`unknown or empty profile: ${JSON.stringify(profile)}`);\n}","typeGuard":"function isKnownProfile(p: string, cfg: ProfileConfig): boolean {\n  return Boolean(cfg.aliases[p]) || p.trim().length > 0;\n}","tryCatchPattern":"try { setDefaultProfile(name); }\ncatch (e) {\n  if (e.message === 'profile is required') {\n    console.error('Usage: config set-default <profile>');\n  } throw e;\n}","preventionTips":["List available profiles before setting a default","Make the CLI argument required in argument parsing","Guard env-sourced profile names for emptiness"],"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"}