errorcore
Capturing Errors

Local Variables

Local variable capture is the shortest path from stack trace to explanation. It tells you what values were in scope when the failure actually happened.

local capture example
const rows = await db.query(
  "select * from invoices where status = ?",
  ["overdue"],
);

const invoice = rows[0];

if (!invoice) {
  throw new Error("disk quota exceeded");
}

In this case the useful signal is not just the thrown error. It is also that rows existed and invoice was undefined. That is often the difference between a fast diagnosis and a guess.

On this page