git.iko.soy/typeable/postgresql-simple
on master help sign in
Throw a better exception from getNotification
commit4cfcdbee22a0cb1fb7985988892264c9d3ed7350 authorLeon P Smith <leon@melding-monads.com> dateThu 27 Jun 2013, 18:38 (13 years ago) parentcf51445
1 file changed+3−4
src/Database/PostgreSQL/Simple/Notification.hs+3−4
src/Database/PostgreSQL/Simple/Notification.hs+3−4
@@ -36,6 +36,7 @@ module Database.PostgreSQL.Simple.Notification
3636
3737import Control.Concurrent
3838import Control.Monad ( when )
39+import Control.Exception ( throwIO )
3940import qualified Data.ByteString as B
4041import Database.PostgreSQL.Simple.Internal
4142import qualified Database.PostgreSQL.LibPQ as PQ
@@ -47,9 +48,6 @@ data Notification = Notification
4748 , notificationData :: !B.ByteString
4849 }
4950
50−errfd :: String
51−errfd = "Database.PostgreSQL.Simple.Notification.getNotification: failed to fetch file descriptor"
52−
5351convertNotice :: PQ.Notify -> Notification
5452convertNotice PQ.Notify{..}
5553 = Notification { notificationPid = notifyBePid
@@ -62,6 +60,7 @@ convertNotice PQ.Notify{..}
6260getNotification :: Connection -> IO Notification
6361getNotification conn = loop False
6462 where
63+ funcName = "Database.PostgreSQL.Simple.Notification.getNotification"
6564 loop doConsume = do
6665 res <- withConnection conn $ \c -> do
6766 when doConsume (PQ.consumeInput c >> return ())
@@ -70,7 +69,7 @@ getNotification conn = loop False
7069 Nothing -> do
7170 mfd <- PQ.socket c
7271 case mfd of
73− Nothing -> fail errfd
72+ Nothing -> throwIO $ fdError funcName
7473 Just fd -> return (Left fd)
7574 Just msg -> return (Right msg)
7675 -- FIXME? what happens if the connection is closed/reset right here?