sickn33/agentic-awesome-skills · error · Error

Out of stock

Error message

Out of stock

What it means

Illustrative domain error from the inventory step of processOrder: checkInventory(order.items) returned { available: false }, so the guard throws 'Out of stock'. The example shows how business-rule failures get modeled as exceptions in imperative code.

Source

Thrown at skills/fp-async/SKILL.md:148

## 2. Chaining Async Operations

### The Problem: Callback Hell / Nested Awaits

```typescript
// BEFORE: Deeply nested, hard to follow
async function processOrder(orderId: string) {
  try {
    const order = await fetchOrder(orderId)
    if (!order) throw new Error('Order not found')

    try {
      const user = await fetchUser(order.userId)
      if (!user) throw new Error('User not found')

      try {
        const inventory = await checkInventory(order.items)
        if (!inventory.available) throw new Error('Out of stock')

        try {
          const payment = await chargePayment(user, order.total)
          if (!payment.success) throw new Error('Payment failed')

          try {
            const shipment = await createShipment(order, user)
            return { order, shipment, payment }
          } catch (e) {
            // Refund payment? Log? What's the state now?
            await refundPayment(payment.id)
            throw e
          }
        } catch (e) {
          throw e
        }
      } catch (e) {
        throw e

View on GitHub (pinned to 58d857988f)

Solutions

  1. Verify actual stock levels for the order's SKUs before retrying
  2. Use optimistic locking or reservation so availability is atomic, removing the race
  3. Model this as an expected Left (business rule) in a TaskEither pipeline instead of a thrown exception
  4. Surface a user-facing 'item unavailable' message with per-item detail rather than a generic error

Example fix

// before
const inventory = await checkInventory(order.items)
if (!inventory.available) throw new Error('Out of stock')
// after
pipe(
  checkInventoryTask(order.items),
  TE.chain(inv => inv.available
    ? TE.right(inv)
    : TE.left(new Error('Out of stock')))
)
Defensive patterns

Strategy: validation

Validate before calling

const inv = await checkInventory(order.items)
if (!inv.available) return { kind: 'OutOfStock', items: inv.unavailableItems ?? order.items }

Type guard

const isInventoryResult = (r: unknown): r is { available: boolean } =>
  typeof r === 'object' && r !== null && typeof (r as any).available === 'boolean'

Try / catch

try {
  // ...
} catch (e) {
  if (e instanceof Error && e.message === 'Out of stock') { /* restock / notify flow */ }
  else throw e
}

Prevention

When it happens

Trigger: Ordering more units than stock on hand; concurrent orders exhausting stock between check and charge; inventory sync lag making the service report unavailable.

Common situations: Flash sales causing races between checkInventory and chargePayment; warehouse sync delays; cart quantities cached client-side and exceeding current stock.

Related errors


AI-assisted analysis of sickn33/agentic-awesome-skills@58d857988f (2026-08-26). Data as JSON: /api/errors/d66bc6a2985691ba. Report an issue: GitHub.