{"record":{"id":"f874fde33a9f914d","repo":"koala73/worldmonitor","slug":"not-found-f874fd","errorCode":"NOT_FOUND","errorMessage":"NOT_FOUND","messagePattern":"NOT_FOUND","errorType":"exception","errorClass":"ConvexError","httpStatus":null,"severity":"error","filePath":"convex/companyMonitoring/companies.ts","lineNumber":202,"sourceCode":"  },\n});\n\nexport const updateCompanyForOwner = internalMutation({\n  args: {\n    ownerUserId: v.string(),\n    companyId: v.string(),\n    patch: companyPatchValidator,\n  },\n  handler: async (ctx, args) => {\n    const account = await requireActiveAccount(ctx, args.ownerUserId);\n    const company = await ctx.db\n      .query(\"companyMonitoringCompanies\")\n      .withIndex(\"by_account_companyId\", (q) =>\n        q.eq(\"ownerAccountId\", account.logicalAccountId).eq(\"companyId\", args.companyId),\n      )\n      .unique();\n    if (!company || company.lifecycle === \"removed\" || !company.name || !company.domicileCountry) {\n      throw new ConvexError(\"NOT_FOUND\");\n    }\n    const patch = args.patch;\n    const addClaimInputs = patch.addClaims ?? [];\n    const removeClaimInputs = patch.removeClaimIds ?? [];\n    if (\n      addClaimInputs.length > COMPANY_MONITORING_LIMITS.maxClaimsPerCompany ||\n      removeClaimInputs.length > COMPANY_MONITORING_LIMITS.maxClaimsPerCompany\n    ) {\n      throw new ConvexError(\"INVALID_COMPANY_PATCH\");\n    }\n\n    const hasName = Object.prototype.hasOwnProperty.call(patch, \"name\");\n    const hasDomicile = Object.prototype.hasOwnProperty.call(patch, \"domicileCountry\");\n    const hasCustomerReference = Object.prototype.hasOwnProperty.call(patch, \"customerReference\");\n    const normalizedFields = normalizeMonitoredCompanyInput({\n      name: hasName ? patch.name! : company.name,\n      domicileCountry: hasDomicile ? patch.domicileCountry! : company.domicileCountry,\n      customerReference: hasCustomerReference","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/convex/companyMonitoring/companies.ts#L184-L220","documentation":"Thrown by the company update mutation (convex/companyMonitoring/companies.ts:202) when no companyMonitoringCompanies row exists for ownerAccountId + companyId, or the row has lifecycle \"removed\", or is missing name or domicileCountry. Updates are only allowed on live, fully-formed companies.","triggerScenarios":"Calling update with a companyId from another account or a typo'd id; updating a company already removed (removal is terminal); updating a company whose required fields were somehow cleared; stale client state referencing a deleted company.","commonSituations":"Two admin sessions where one removed the company; client caches holding an old company list; id mix-ups between environments (staging id sent to production); import scripts re-running against already-removed rows.","solutions":["Refresh the company list and confirm the id still exists with lifecycle active/paused before showing an edit form","If the company was removed, create a new company instead of updating the dead id","Verify you are calling with the correct ownerUserId (the account that owns the company)","Handle NOT_FOUND by returning the user to the list view rather than retrying"],"exampleFix":"// before\nawait api.companyMonitoring.updateCompany({ ownerUserId, companyId, patch });\n\n// after\nconst company = await api.companyMonitoring.getCompany({ ownerUserId, companyId });\nif (!company || company.lifecycle === \"removed\") {\n  router.replace(\"/companies\"); // stale reference; reload list\n  return;\n}\nawait api.companyMonitoring.updateCompany({ ownerUserId, companyId, patch });","handlingStrategy":"validation","validationCode":"const company = await api.companyMonitoring.getCompany({ ownerUserId, companyId });\nconst updatable = !!company && company.lifecycle !== \"removed\" && !!company.name && !!company.domicileCountry;\nif (!updatable) {\n  throw new UserFacingError(\"Company not found or no longer editable.\");\n}\nawait api.companyMonitoring.updateCompany({ ownerUserId, companyId, patch });","typeGuard":"function isEditableCompany(company: { lifecycle: string; name?: string; domicileCountry?: string } | null | undefined): company is { lifecycle: string; name: string; domicileCountry: string } {\n  return !!company && company.lifecycle !== \"removed\" && typeof company.name === \"string\" && typeof company.domicileCountry === \"string\";\n}","tryCatchPattern":"try {\n  await api.companyMonitoring.updateCompany({ ownerUserId, companyId, patch });\n} catch (err) {\n  if (err instanceof ConvexError && err.data === \"NOT_FOUND\") {\n    router.replace(\"/companies\"); // stale reference — reload the list\n    return;\n  }\n  throw err;\n}","preventionTips":["Load the company fresh before rendering an edit form; do not trust cached lists","Send users back to the list view on NOT_FOUND instead of retrying","Confirm ownerUserId matches the account that owns the company","Treat removed companies as gone: offer creation, not editing"],"tags":["convex","not-found","lifecycle","update","mutation"],"backgroundTag":"resource-not-found","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}