nikita-volkov / hasql

The fastest PostgreSQL libpq-based driver for Haskell
http://hackage.haskell.org/package/hasql
MIT License
517 stars 54 forks source link

More information in decoding errors #142

Open guaraqe opened 2 years ago

guaraqe commented 2 years ago

When there is a decoding error, it is common to have something like:

ResultError (RowError 0 UnexpectedNull)

which shows the error, but lacks details, which can be difficult to debug, especially in very large queries. Would it be possible to return the full row that is supposed to be decoded, as well as the index in the row where the failure occurred? It seems that decoding happens in Haskell, so that should be possible.

nikita-volkov commented 2 years ago

Yeah, something like that is possible. Actually this issue can be divided into three:

  1. Extend RowError with the index of the failed column. Not very hard.
  2. Extend ResultError with meta info about the structure of the result. This involves processing column OIDs. OID is how Postgres identifies the types. Must be noted that there are some complications involved in regards to composite and array types. So, this one is complicated.
  3. Match the user-supplied decoders against that meta info. See https://github.com/nikita-volkov/hasql/issues/97

I don't plan to develop these features myself, since my effort is focused on a native Postgres driver project now. https://twitter.com/NikitaYVolkov/status/1452985041366175750. It's likely that I'll address these issues there. As for addressing this in Hasql, PRs are welcome!.

guaraqe commented 2 years ago

The first one would be very useful already. If you give me some pointers on where to start, I think I can free some time to do it.

nikita-volkov commented 2 years ago

It's all in this module: https://github.com/nikita-volkov/hasql/blob/9931a98a26cb8c3a12fe2c0844d6a480b81d0a14/library/Hasql/Private/Decoders/Row.hs