Keep the original error in cause when you wrap it
Catch an error and throw a nicer one, and you lose the stack that actually explains what happened. cause keeps both.
try {
await sql`...`;
} catch (err) {
throw new Error(`failed to save order ${id}`, { cause: err });
}Error reporters and console.error print the whole chain. Your message says what you were trying to do, and the cause says what went wrong.
typescriptdebugging