{"record":{"id":"d4d161f16ad61768","repo":"paperclipai/paperclip","slug":"invalid-by-mode-opts-by-expected-one-of-a","errorCode":null,"errorMessage":"Invalid --by mode '${opts.by}'. Expected one of: auto, id, prefix.","messagePattern":"Invalid --by mode '(.+?)'\\. Expected one of: auto, id, prefix\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/company.ts","lineNumber":1933,"sourceCode":"    company\n      .command(\"delete\")\n      .description(\"Delete a company by ID or shortname/prefix (destructive)\")\n      .argument(\"<selector>\", \"Company ID or issue prefix (for example PAP)\")\n      .option(\n        \"--by <mode>\",\n        \"Selector mode: auto | id | prefix\",\n        \"auto\",\n      )\n      .option(\"--yes\", \"Required safety flag to confirm destructive action\", false)\n      .option(\n        \"--confirm <value>\",\n        \"Required safety value: target company ID or shortname/prefix\",\n      )\n      .action(async (selector: string, opts: CompanyDeleteOptions) => {\n        try {\n          const by = (opts.by ?? \"auto\").trim().toLowerCase() as CompanyDeleteSelectorMode;\n          if (![\"auto\", \"id\", \"prefix\"].includes(by)) {\n            throw new Error(`Invalid --by mode '${opts.by}'. Expected one of: auto, id, prefix.`);\n          }\n\n          const ctx = resolveCommandContext(opts);\n          const normalizedSelector = normalizeSelector(selector);\n          assertDeleteFlags(opts);\n\n          let target: Company | null = null;\n          const shouldTryIdLookup = by === \"id\" || (by === \"auto\" && isUuidLike(normalizedSelector));\n          if (shouldTryIdLookup) {\n            const byId = await ctx.api.get<Company>(apiPath`/api/companies/${normalizedSelector}`, { ignoreNotFound: true });\n            if (byId) {\n              target = byId;\n            } else if (by === \"id\") {\n              throw new Error(`No company found by ID '${normalizedSelector}'.`);\n            }\n          }\n\n          if (!target && ctx.companyId) {","sourceCodeStart":1915,"sourceCodeEnd":1951,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/company.ts#L1915-L1951","documentation":"Thrown at the start of the `company delete <selector>` action when `opts.by` (defaulted to \"auto\", trimmed+lowercased) is not one of auto/id/prefix. The --by flag controls how the selector is interpreted: auto (detect), id (UUID lookup), or prefix (issue prefix match).","triggerScenarios":"Passing `--by name`, `--by uuid`, `--by shortname`, or any token outside the three allowed; a typo like `--by pref`.","commonSituations":"Developer guesses 'name' or 'uuid' as the by-mode; copying a flag value from documentation that used different terms.","solutions":["Use `--by auto`, `--by id`, or `--by prefix`.","Omit --by entirely to default to 'auto', which tries ID-then-prefix resolution.","Run `paperclipai company delete --help` to confirm accepted values."],"exampleFix":"# before\npaperclipai company delete acme --by name --yes --confirm ACME\n# after\npaperclipai company delete acme --by prefix --yes --confirm ACME","handlingStrategy":"validation","validationCode":"const BY_MODES = [\"auto\", \"id\", \"prefix\"] as const;\ntype ByMode = typeof BY_MODES[number];\nfunction normalizeByMode(v: string | undefined): ByMode {\n  const lower = (v ?? \"auto\").trim().toLowerCase();\n  if (!BY_MODES.includes(lower as ByMode)) {\n    throw new Error(`--by must be one of ${BY_MODES.join(\", \")}`);\n  }\n  return lower as ByMode;\n}","typeGuard":"function isByMode(v: unknown): v is \"auto\" | \"id\" | \"prefix\" {\n  return typeof v === \"string\" && [\"auto\", \"id\", \"prefix\"].includes(v.toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Default to omitting --by (auto) unless you need to force a resolution mode.","Share the allow-list across wrappers and docs.","Add a regression test for unknown --by values in CLI smoke tests."],"tags":["cli","validation","company-delete","invalid-flag"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}