{"record":{"id":"5654f7939986bb82","repo":"koala73/worldmonitor","slug":"claim-not-found","errorCode":null,"errorMessage":"CLAIM_NOT_FOUND","messagePattern":"CLAIM_NOT_FOUND","errorType":"exception","errorClass":"ConvexError","httpStatus":null,"severity":"error","filePath":"convex/companyMonitoring/companies.ts","lineNumber":246,"sourceCode":"        normalizedFields.customerReference,\n      );\n      if (conflict && conflict.companyId !== company.companyId) {\n        throw new ConvexError(\"CUSTOMER_REFERENCE_CONFLICT\");\n      }\n    }\n\n    const currentClaims = await ctx.db\n      .query(\"companyMonitoringClaims\")\n      .withIndex(\"by_account_company\", (q) =>\n        q.eq(\"ownerAccountId\", account.logicalAccountId).eq(\"companyId\", company.companyId),\n      )\n      .collect();\n    const currentById = new Map(currentClaims.map((claim) => [claim.claimId, claim]));\n    const removeIds = new Set(\n      removeClaimInputs.map((claimId) => assertLogicalId(\"claim\", String(claimId))),\n    );\n    for (const claimId of removeIds) {\n      if (!currentById.has(claimId)) throw new ConvexError(\"CLAIM_NOT_FOUND\");\n    }\n    if (hasCustomerReference && normalizedFields.customerReference !== company.customerReference) {\n      for (const claim of currentClaims) {\n        if (claim.type === \"customer_reference\") removeIds.add(claim.claimId);\n      }\n    }\n\n    const remainingKeys = new Set(\n      currentClaims\n        .filter((claim) => !removeIds.has(claim.claimId))\n        .map((claim) => `${claim.type}\\u0000${claim.value}`),\n    );\n    const normalizedAdditions = addClaimInputs.map(normalizeCompanyClaimInput);\n    if (normalizedFields.name !== company.name) {\n      normalizedAdditions.unshift({ type: \"alias\", value: normalizedFields.name });\n    }\n    if (hasCustomerReference && normalizedFields.customerReference) {\n      normalizedAdditions.push({","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/koala73/worldmonitor/blob/ffec79ac339946fd2d24e85845da5755dcaa534b/convex/companyMonitoring/companies.ts#L228-L264","documentation":"Thrown by updateCompanyForOwner when a claim id listed in removeClaimIds does not correspond to any existing claim on the target company. Each removal id is validated against the by_account_company claims map (currentById) built from the live claim rows, so the id must be a real claimId owned by that company.","triggerScenarios":"Passing a removeClaimIds entry that is not a current claimId of the patched company: a stale id, an id from a different company, an id already removed in a concurrent update, or a malformed logical id.","commonSituations":"UI caching a claim list that has since changed; concurrent edits where one removes a claim another is also removing; copy/paste of a claim id across companies.","solutions":["Refresh the company's current claims before issuing the removal patch.","Tolerate already-removed claims client-side by filtering the removeClaimIds to only those still present.","If the removal is best-effort, split removals so a missing one does not abort the whole patch."],"exampleFix":"// before\nawait update({ companyId, patch: { removeClaimIds: cachedIds } });\n\n// after\nconst claims = await listClaims(companyId);\nconst stillPresent = cachedIds.filter((id) => claims.some((c) => c.claimId === id));\nawait update({ companyId, patch: { removeClaimIds: stillPresent } });","handlingStrategy":"validation","validationCode":"const current = await listClaimsForCompany(ownerUserId, companyId);\nconst knownIds = new Set(current.map((c) => c.claimId));\nconst validRemovals = removeClaimIds.filter((id) => knownIds.has(id));\nawait updateCompanyForOwner({ ownerUserId, companyId, patch: { removeClaimIds: validRemovals } });","typeGuard":"function everyRemovalExists(current: { claimId: string }[], removals: string[]): boolean {\n  const known = new Set(current.map((c) => c.claimId));\n  return removals.every((id) => known.has(id));\n}","tryCatchPattern":null,"preventionTips":["Refresh the claim list before issuing removals.","Filter client-side to ids still present to tolerate concurrent edits."],"tags":["convex","not-found","claims","company-monitoring"],"backgroundTag":null,"analyzedSha":"ffec79ac339946fd2d24e85845da5755dcaa534b","analyzedAt":"2026-08-12T11:24:56.012Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}