@@ -29,6 +29,7 @@ import Foreign.Marshal.Utils
2929import Foreign.Ptr
3030import Foreign.Storable
3131import GHC.Exts
32+ import GHC.Stack
3233
3334import Database.PostgreSQL.PQTypes.Internal.C.Interface
3435import Database.PostgreSQL.PQTypes.Internal.C.Types
@@ -82,12 +83,12 @@ textToCString bs = unsafeUseAsCStringLen (T.encodeUtf8 bs) $ \(cs, len) -> do
8283
8384-- | Check return value of a function from libpqtypes
8485-- and if it indicates an error, throw appropriate exception.
85- verifyPQTRes :: Ptr PGerror -> String -> CInt -> IO ()
86+ verifyPQTRes :: HasCallStack => Ptr PGerror -> String -> CInt -> IO ()
8687verifyPQTRes err ctx 0 = throwLibPQTypesError err ctx
8788verifyPQTRes _ _ _ = pure ()
8889
8990-- 'alloca'-like function for managing usage of 'PGparam' object.
90- withPGparam :: Ptr PGconn -> (Ptr PGparam -> IO r ) -> IO r
91+ withPGparam :: HasCallStack => Ptr PGconn -> (Ptr PGparam -> IO r ) -> IO r
9192withPGparam conn = E. bracket create c_PQparamClear
9293 where
9394 create = alloca $ \ err -> do
@@ -99,21 +100,21 @@ withPGparam conn = E.bracket create c_PQparamClear
99100----------------------------------------
100101
101102-- | Throw libpq specific error.
102- throwLibPQError :: Ptr PGconn -> String -> IO a
103+ throwLibPQError :: HasCallStack => Ptr PGconn -> String -> IO a
103104throwLibPQError conn ctx = do
104105 msg <- safePeekCString' =<< c_PQerrorMessage conn
105106 E. throwIO . LibPQError $
106107 if null ctx then msg else ctx ++ " : " ++ msg
107108
108109-- | Throw libpqtypes specific error.
109- throwLibPQTypesError :: Ptr PGerror -> String -> IO a
110+ throwLibPQTypesError :: HasCallStack => Ptr PGerror -> String -> IO a
110111throwLibPQTypesError err ctx = do
111112 msg <- pgErrorMsg <$> peek err
112113 E. throwIO . LibPQError $
113114 if null ctx then msg else ctx ++ " : " ++ msg
114115
115116-- | Rethrow supplied exception enriched with array index.
116- rethrowWithArrayError :: CInt -> E. SomeException -> IO a
117+ rethrowWithArrayError :: HasCallStack => CInt -> E. SomeException -> IO a
117118rethrowWithArrayError i (E. SomeException e) =
118119 E. throwIO
119120 ArrayItemError
@@ -122,9 +123,9 @@ rethrowWithArrayError i (E.SomeException e) =
122123 }
123124
124125-- | Throw 'HPQTypesError exception.
125- hpqTypesError :: String -> IO a
126+ hpqTypesError :: HasCallStack => String -> IO a
126127hpqTypesError = E. throwIO . HPQTypesError
127128
128129-- | Throw 'unexpected NULL' exception.
129- unexpectedNULL :: IO a
130+ unexpectedNULL :: HasCallStack => IO a
130131unexpectedNULL = hpqTypesError " unexpected NULL"
0 commit comments