Debug a production error from logs

Skill
Debugging production
Time
About 30 min
Access
Full track

Customers say they sometimes don’t get a receipt after paying. Others say they got two. The handler below runs whenever the payment provider sends an order.paid webhook. If the handler throws, the provider retries the webhook up to 3 times.

Here are the logs from a ten-minute window, and the code. AI is very good at reading stack traces; it’s less good at noticing what the logs don’t say. Read both carefully.

Logs

text
10:14:03 INFO  order.paid  orderId=ord_8812 source=web userId=u_102310:14:04 INFO  receipt.sent orderId=ord_8812 to=a***@gmail.com10:14:09 WARN  db.orders.update slow query (5,200 ms) orderId=ord_881210:14:09 ERROR webhook timeout after 5000 ms orderId=ord_881210:15:11 INFO  order.paid  orderId=ord_8813 source=guest_checkout userId=null10:15:11 ERROR TypeError: Cannot read properties of null (reading 'email')               at handleOrderPaid (orders/paid.js:6:26)10:15:41 INFO  order.paid  orderId=ord_8813 source=guest_checkout userId=null (retry 1)10:15:41 ERROR TypeError: Cannot read properties of null (reading 'email')               at handleOrderPaid (orders/paid.js:6:26)10:16:20 INFO  order.paid  orderId=ord_8812 source=web userId=u_1023 (retry 1)10:16:21 INFO  receipt.sent orderId=ord_8812 to=a***@gmail.com

Submit

  • The root cause of each problem (there is more than one)
  • Your fixed handler
  • How you’d make sure this can’t come back (a test, a check, or a change to how the handler works)
orders/paid.js
// orders/paid.js// Orders: { id, userId: string | null, guestEmail: string | null, receiptSent: boolean, ... }async function handleOrderPaid(event) {  const order = await db.orders.findById(event.orderId);  const user = await db.users.findById(order.userId);  await sendReceipt(user.email, order);  await db.orders.update(order.id, { receiptSent: true });} module.exports = { handleOrderPaid };

This task is in the full track

You can read the brief above. To submit it, unlock all 10 tasks for $9, once. Unlimited resubmissions, and a full refund within 7 days if it isn’t useful.

Create a free account to get your review

Your answer stays here. Reviews are saved to your account so you can come back to them.

or with email

At least 8 characters, with a number and both upper and lower case letters.

Already have an account?