Ask HN: How do you handle recoverable errors?
Example scenario: SQL query returns data different than what the query types says it will.
We know this because we validate all data at runtime.
const userAccount = await pool.one(sql.type(
z.object({
id: z.number(),
firstName: z.string(),
lastName: z.string(),
postHogId: z.string(),
})
)`
SELECT
id,
first_name,
last_name
FROM user_account
`);
(In this example, this types say that we are expecting `postHogId`, but the query does not return that data.)If we swallow the error (and report it in the background), user _might_ still be able to complete their journey. That is b/c just because types do not match, it does not 100% guarantee that the rest of the app will break.
The trade-off is that if we allow unexpected data to flow, it might corrupt the data further down the line. Very hard to recover if this happens at scale. Could also result in pretty gruesome outcomes if query involves financial data.
Which strategy does your application take?