Keep the original error in cause when you wrap it
Catching an error and throwing a nicer one loses the stack that actually explains it. 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 chain. The message says what you were doing, the cause says what went wrong.
typescriptdebugging