{"record":{"id":"7919d31698302884","repo":"koala73/worldmonitor","slug":"invalid-country","errorCode":"INVALID_COUNTRY","errorMessage":"INVALID_COUNTRY","messagePattern":"INVALID_COUNTRY","errorType":"validation","errorClass":"ConvexError","httpStatus":null,"severity":"error","filePath":"convex/followedCountries.ts","lineNumber":347,"sourceCode":" *\n * Without Tier 1, two parallel first-ever mutations could both read\n * `meta=undefined`, both INSERT, and produce duplicate meta rows that\n * break the `.unique()` read AND re-open the cap-bypass window. With\n * Tier 1 in place, the brand-new-user race is closed deterministically.\n *\n * Errors are typed `ConvexError({kind, ...})` with object data so callers\n * can branch on `err.data.kind` (memory:\n * `convex-error-string-data-strips-errordata-on-wire`).\n */\nexport const followCountry = mutation({\n  args: { country: v.string() },\n  handler: async (ctx, args): Promise<FollowMutationResult> => {\n    const identity = await ctx.auth.getUserIdentity();\n    if (!identity) throw new ConvexError({ kind: \"UNAUTHENTICATED\" });\n    const userId = identity.subject;\n\n    if (!isValidIso2(args.country)) {\n      throw new ConvexError({\n        kind: \"INVALID_COUNTRY\",\n        country: args.country,\n      });\n    }\n\n    // Tier-1 lock: pre-seeded shard row. Read at top, patch at end.\n    const shard = await readShardOrThrow(ctx, userId);\n\n    // Tier-2 read: per-user denormalized count (lazy-created, but safe\n    // under the shard lock above).\n    const { meta, count: currentCount } = await readUserMeta(ctx, userId);\n\n    const existingRow = await ctx.db\n      .query(\"followedCountries\")\n      .withIndex(\"by_user_country\", (q) =>\n        q.eq(\"userId\", userId).eq(\"country\", args.country),\n      )\n      .first();","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/koala73/worldmonitor/blob/eeab0a219fce0f02a00603b532dbae9041b934ac/convex/followedCountries.ts#L329-L365","documentation":"Validation sentinel in followCountry: the supplied country identifier is not a recognized or valid country code in the followed-countries domain. Typed as ConvexError with object data (kind 'INVALID_COUNTRY') so clients branch on err.data.kind.","triggerScenarios":"Thrown at convex/followedCountries.ts:347 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Send the canonical country code from the country list the UI already renders","Validate the code against the supported country set client-side before calling followCountry"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"eeab0a219fce0f02a00603b532dbae9041b934ac","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}