{"record":{"id":"1fe9ba90520b9ebf","repo":"sickn33/agentic-awesome-skills","slug":"user-not-found","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/fp-async/SKILL.md","lineNumber":144,"sourceCode":")\n```\n\n---\n\n## 2. Chaining Async Operations\n\n### The Problem: Callback Hell / Nested Awaits\n\n```typescript\n// BEFORE: Deeply nested, hard to follow\nasync function processOrder(orderId: string) {\n  try {\n    const order = await fetchOrder(orderId)\n    if (!order) throw new Error('Order not found')\n\n    try {\n      const user = await fetchUser(order.userId)\n      if (!user) throw new Error('User not found')\n\n      try {\n        const inventory = await checkInventory(order.items)\n        if (!inventory.available) throw new Error('Out of stock')\n\n        try {\n          const payment = await chargePayment(user, order.total)\n          if (!payment.success) throw new Error('Payment failed')\n\n          try {\n            const shipment = await createShipment(order, user)\n            return { order, shipment, payment }\n          } catch (e) {\n            // Refund payment? Log? What's the state now?\n            await refundPayment(payment.id)\n            throw e\n          }\n        } catch (e) {","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/sickn33/agentic-awesome-skills/blob/58d857988fcfac6986206bca2b2fe223aa437e4b/skills/fp-async/SKILL.md#L126-L162","documentation":"Illustrative domain error in the processOrder BEFORE snippet: the order exists but fetchUser(order.userId) returned null/undefined, so the guard throws 'User not found'. It is the second level of the nested-try pyramid the skill wants to flatten.","triggerScenarios":"Order rows referencing a userId with no matching user record (deleted user, orphaned foreign key, wrong-environment database).","commonSituations":"Data migrated without foreign-key enforcement; users soft-deleted but orders retained; cross-environment data drift where orders exist in staging but users do not.","solutions":["Query the users table for order.userId to confirm the reference is dangling","Fix the data: restore the user, reassign the order, or add FK constraints to prevent orphans","Refactor with TE.fromNullable to surface 'User not found' as a Left value in a flat pipeline","Guard upstream: block order creation when the owning user is missing"],"exampleFix":"// before\nconst user = await fetchUser(order.userId)\nif (!user) throw new Error('User not found')\n// after\npipe(\n  fetchOrderTask(orderId),\n  TE.chain(order => fetchUserTask(order.userId)),\n  TE.chain(user => user == null\n    ? TE.left(new Error('User not found'))\n    : TE.right(user))\n)","handlingStrategy":"validation","validationCode":"const user = await fetchUser(order.userId)\nif (user == null) return { kind: 'UserNotFound', userId: order.userId }","typeGuard":"const isUser = (u: unknown): u is User =>\n  typeof u === 'object' && u !== null && 'id' in u && typeof (u as User).id === 'string'","tryCatchPattern":"catch (e) {\n  if (e instanceof Error && e.message === 'User not found') { /* show account-missing UI */ }\n  else throw e\n}","preventionTips":["Enforce foreign keys so orders cannot reference missing users","Treat a dangling userId as a data-integrity incident, not a user error","Model each not-found as a tagged Left in the pipeline"],"tags":["documentation","domain-error","null-check","data-integrity"],"backgroundTag":"entity-not-found","analyzedSha":"58d857988fcfac6986206bca2b2fe223aa437e4b","analyzedAt":"2026-08-26T11:55:59.350Z","schemaVersion":2},"datasetVersion":"2026-08-26T14:46:13.012Z"}