{"record":{"id":"a73dca3596e828de","repo":"paperclipai/paperclip","slug":"invalid-target-value-use-new-existing","errorCode":null,"errorMessage":"Invalid --target value. Use: new | existing","messagePattern":"Invalid --target value\\. Use: new \\| existing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/company.ts","lineNumber":1678,"sourceCode":"          }\n          const ctx = resolveCommandContext(opts);\n          const interactiveView = isInteractiveTerminal() && !ctx.json;\n          const from = fromPathOrUrl.trim();\n          if (!from) {\n            throw new Error(\"Source path or URL is required.\");\n          }\n\n          const include = resolveImportInclude(opts.include);\n          const agents = parseAgents(opts.agents);\n          const collision = (opts.collision ?? \"rename\").toLowerCase() as CompanyCollisionMode;\n          if (![\"rename\", \"skip\", \"replace\"].includes(collision)) {\n            throw new Error(\"Invalid --collision value. Use: rename, skip, replace\");\n          }\n\n          const inferredTarget = opts.target ?? (opts.companyId || ctx.companyId ? \"existing\" : \"new\");\n          const target = inferredTarget.toLowerCase() as CompanyImportTargetMode;\n          if (![\"new\", \"existing\"].includes(target)) {\n            throw new Error(\"Invalid --target value. Use: new | existing\");\n          }\n\n          const existingTargetCompanyId = opts.companyId?.trim() || ctx.companyId;\n          const targetPayload =\n            target === \"existing\"\n              ? {\n                  mode: \"existing_company\" as const,\n                  companyId: existingTargetCompanyId,\n                }\n              : {\n                  mode: \"new_company\" as const,\n                  newCompanyName: opts.newCompanyName?.trim() || null,\n                };\n\n          if (targetPayload.mode === \"existing_company\" && !targetPayload.companyId) {\n            throw new Error(\"Target existing company requires --company-id (or context default companyId).\");\n          }\n","sourceCodeStart":1660,"sourceCodeEnd":1696,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/company.ts#L1660-L1696","documentation":"Thrown when `opts.target` lowercased is neither 'new' nor 'existing'. The --target flag selects whether import creates a brand-new company or imports into an existing one. Note target is inferred when omitted (new vs existing based on companyId context), so this throw only fires on an explicit, invalid value.","triggerScenarios":"Passing `--target create`, `--target current`, `--target both`, or any value outside the two allowed tokens.","commonSituations":"Developer assumes 'create' is the verb for new companies; copying flag vocabulary from another CLI; typo from `--target exitsting`.","solutions":["Use `--target new` (create a company) or `--target existing` (import into an existing one).","Omit --target entirely to let the CLI infer it from whether --company-id is present.","Check `paperclipai company import --help` for the canonical values."],"exampleFix":"# before\npaperclipai company import ./src --target create\n# after\npaperclipai company import ./src --target new","handlingStrategy":"validation","validationCode":"const TARGET_MODES = [\"new\", \"existing\"] as const;\ntype TargetMode = typeof TARGET_MODES[number];\nfunction normalizeTarget(v: string | undefined, hasCompanyId: boolean): TargetMode {\n  const lower = (v ?? (hasCompanyId ? \"existing\" : \"new\")).trim().toLowerCase();\n  if (!TARGET_MODES.includes(lower as TargetMode)) {\n    throw new Error(`Invalid target '${v}'; expected new or existing`);\n  }\n  return lower as TargetMode;\n}","typeGuard":"function isTargetMode(v: unknown): v is \"new\" | \"existing\" {\n  return typeof v === \"string\" && [\"new\", \"existing\"].includes(v.toLowerCase());\n}","tryCatchPattern":null,"preventionTips":["Let the CLI infer the target by omitting --target when behavior is unambiguous.","Document the new/existing distinction in onboarding scripts.","Validate user-supplied target against the allow-list in wrappers."],"tags":["cli","validation","import","invalid-flag"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}