git.iko.soy/typeable/postgresql-simple
on master help sign in
Copy: Show error message on failure

This ensures that the exception thrown includes the cause. Sadly it seems that the only way to determine that a COPY IN has failed is to fail to parse the row count. It seems that all of the getResults calls after the putCopyEnd command inexplicably return success, despite the fact that something failed.

commit5ce5d2ecbc397e6c38b75520d37ff5b5bd0b3ea1 authorBen Gamari <ben@smart-cactus.org> dateThu 19 May 2016, 16:01 (10 years ago) parent1e366a2
1 file changed+3−1
src/Database/PostgreSQL/Simple/Copy.hs+3−1
src/Database/PostgreSQL/Simple/Copy.hs+3−1
@@ -224,7 +224,9 @@ getCopyCommandTag funcName pqconn = do
224224 consumeResults pqconn
225225 let rowCount = P.string "COPY " *> (P.decimal <* P.endOfInput)
226226 case P.parseOnly rowCount cmdStat of
227− Left _ -> fail errCmdStatusFmt
227+ Left _ -> do mmsg <- PQ.errorMessage pqconn
228+ fail $ errCmdStatusFmt
229+ ++ maybe "" (\msg -> "\nConnection error: "++B.unpack msg) mmsg
228230 Right n -> return $! n
229231 where
230232 errCmdStatus = B.unpack funcName ++ ": failed to fetch command status"