{"record":{"id":"16a5b2c3c7b6848f","repo":"can1357/oh-my-pi","slug":"alias-requires-profile-name-or-omp-profile","errorCode":null,"errorMessage":"--alias requires --profile <name> or OMP_PROFILE","messagePattern":"--alias requires --profile <name> or OMP_PROFILE","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/cli.ts","lineNumber":364,"sourceCode":"\t\tconst extracted = extractProfileFlags(resolvedArgv);\n\t\tresolvedArgv = extracted.argv;\n\t\tif (extracted.profile !== undefined) {\n\t\t\tsetProfile(extracted.profile);\n\t\t} else {\n\t\t\t// No explicit --profile: activate any OMP_PROFILE/PI_PROFILE inherited\n\t\t\t// from the environment. Module-load resolution deliberately swallows an\n\t\t\t// invalid value to avoid an uncaught throw before this try/catch is in\n\t\t\t// scope (see `readProfileFromEnvSafe` in dirs.ts), and callers may set\n\t\t\t// OMP_PROFILE after importing this module (profile aliases/tests). Surfacing\n\t\t\t// validation here turns `OMP_PROFILE=.. omp --version` into a clean error;\n\t\t\t// calling setProfile keeps every later path helper on the env-selected\n\t\t\t// profile instead of the default agent directory.\n\t\t\tsetProfile(resolveProfileEnv(process.env.OMP_PROFILE, process.env.PI_PROFILE));\n\t\t}\n\t\tif (extracted.aliasName !== undefined) {\n\t\t\tconst profile = extracted.profile ?? getActiveProfile();\n\t\t\tif (!profile) {\n\t\t\t\tthrow new Error(\"--alias requires --profile <name> or OMP_PROFILE\");\n\t\t\t}\n\t\t\tconst result = await installProfileAlias({\n\t\t\t\tprofile,\n\t\t\t\taliasName: extracted.aliasName,\n\t\t\t\tcommand: resolveProfileAliasCommandFromProcess(),\n\t\t\t});\n\t\t\tprocess.stdout.write(\n\t\t\t\t`Created ${result.aliasName} for profile ${result.profile} in ${result.configPath}\\n` +\n\t\t\t\t\t`Restart your shell or run: ${result.reloadedWith}\\n` +\n\t\t\t\t\t`Then use: ${result.aliasName} update, ${result.aliasName} --version, or ${result.aliasName}\\n`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`Error: ${message}\\n`);\n\t\tprocess.exitCode = 1;\n\t\treturn;","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/cli.ts#L346-L382","documentation":"Argument-validation error thrown by runCli: the user passed --alias to install a command alias, but no profile was specified either via --profile on the same invocation or via the OMP_PROFILE (or legacy PI_PROFILE) environment variable. Aliases are namespaced per profile, so the CLI refuses to guess which profile the alias belongs to.","triggerScenarios":"Invoking the CLI with `--alias <name>` while `extracted.profile` is undefined and getActiveProfile() returns null — i.e. neither --profile <name> nor OMP_PROFILE/PI_PROFILE was set for this invocation.","commonSituations":"Scripting alias setup in CI without setting OMP_PROFILE; forgetting that --profile must accompany --alias on the same command line; relying on a profile that was never set as active in the environment.","solutions":["Add --profile <name> to the same command as --alias","Set the OMP_PROFILE environment variable (or legacy PI_PROFILE) to the target profile","Verify getActiveProfile/resolveProfileEnv are receiving the env var (check shell/export context in scripts)","If scripting, pass both flags explicitly: `omp --profile work --alias myalias`"],"exampleFix":"// before (fails)\nomp --alias deploy\n// after\nomp --profile work --alias deploy\n// or\nexport OMP_PROFILE=work\nomp --alias deploy","handlingStrategy":"validation","validationCode":"function canInstallAlias(args: { alias?: string; profile?: string }, env: NodeJS.ProcessEnv): boolean {\n\treturn !args.alias || Boolean(args.profile || env.OMP_PROFILE || env.PI_PROFILE);\n}","typeGuard":"function aliasInvocationHasProfile(args: { aliasName?: string; profile?: string }, env: NodeJS.ProcessEnv): boolean {\n\treturn args.aliasName === undefined || (args.profile !== undefined || Boolean(env.OMP_PROFILE ?? env.PI_PROFILE));\n}","tryCatchPattern":"try {\n\tawait runCli(argv);\n} catch (err) {\n\tif (err.message.includes(\"--alias requires --profile\")) {\n\t\tconsole.error(\"Usage: omp --profile <name> --alias <alias> (or set OMP_PROFILE)\");\n\t\tprocess.exitCode = 1;\n\t} else throw err;\n}","preventionTips":["Always pass --profile together with --alias in scripts and CI","Set OMP_PROFILE in shell profiles/CI env when working against a non-default profile","Remember PI_PROFILE is the legacy env var; migrate scripts to OMP_PROFILE"],"tags":["cli","arguments","profile","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}