paperclipai/paperclip · error · Error

Could not resolve company "${selector}" in both source and t

Error message

Could not resolve company "${selector}" in both source and target databases.

What it means

Thrown by resolveMergeCompany when an explicit company selector was passed (--company) but no company in the SHARED set matches it by id OR by issuePrefix (case-insensitive). 'Shared' means companies whose id exists in BOTH source and target databases. The selector must therefore identify one of the companies present on both sides, not just one side.

Source

Thrown at cli/src/commands/worktree.ts:2330

      .from(companies),
    input.targetDb
      .select({
        id: companies.id,
        name: companies.name,
        issuePrefix: companies.issuePrefix,
      })
      .from(companies),
  ]);

  const targetById = new Map(targetCompanies.map((company) => [company.id, company]));
  const shared = sourceCompanies.filter((company) => targetById.has(company.id));
  const selector = nonEmpty(input.selector);
  if (selector) {
    const matched = shared.find(
      (company) => company.id === selector || company.issuePrefix.toLowerCase() === selector.toLowerCase(),
    );
    if (!matched) {
      throw new Error(`Could not resolve company "${selector}" in both source and target databases.`);
    }
    return matched;
  }

  if (shared.length === 1) {
    return shared[0];
  }

  if (shared.length === 0) {
    throw new Error("Source and target databases do not share a company id. Pass --company explicitly once both sides match.");
  }

  const options = shared
    .map((company) => `${company.issuePrefix} (${company.name})`)
    .join(", ");
  throw new Error(`Multiple shared companies found. Re-run with --company <id-or-prefix>. Options: ${options}`);
}

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. List shared companies by running merge-history WITHOUT --company and reading the 'Multiple shared companies' options, or query both DBs for matching company ids.
  2. Use the company id (preferred) or exact issuePrefix of a company present in both source and target.
  3. If the target lacks the company, ensure it was seeded/created before merging.
  4. Check for trailing whitespace / case in the selector.

Example fix

// before
paperclipai worktree:merge-history --company ABC   # ABC only in source
// after (use a shared id)
paperclipai worktree:merge-history --company 01HXXXXXXXXXXXXXXXXXXXXXX
Defensive patterns

Strategy: validation

Validate before calling

const shared = sourceCompanies.filter((c) => targetById.has(c.id));
const matched = shared.find((c) => c.id === selector || c.issuePrefix.toLowerCase() === selector.toLowerCase());
if (!matched) throw new Error(`Selector not in shared set`);

Type guard

function selectorMatchesShared(selector: string, shared: { id: string; issuePrefix: string }[]): boolean {
  const s = selector.toLowerCase();
  return shared.some((c) => c.id === selector || c.issuePrefix.toLowerCase() === s);
}

Prevention

When it happens

Trigger: Passing `--company <id>` where the id exists only in source or only in target; passing an issuePrefix that belongs to a non-shared company; typo in the selector; copy-pasting a source-only company id.

Common situations: Freshly seeded target that doesn't yet contain the source company; merged company id mismatch after a re-seed; selector taken from the wrong database.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/14921edd6690a592. Report an issue: GitHub.