In case of exception, report the offending function

This commit is contained in:
krangelov
2021-09-17 11:22:18 +02:00
parent 3f31d86d0d
commit ddb01b41be
3 changed files with 29 additions and 26 deletions

View File

@@ -219,12 +219,15 @@ utf8Length s = count 0 s
-----------------------------------------------------------------------
-- Exceptions
newtype PGFError = PGFError String
deriving (Show, Typeable)
data PGFError = PGFError String String
deriving Typeable
instance Show PGFError where
show (PGFError loc msg) = loc++": "++msg
instance Exception PGFError
withPgfExn f =
withPgfExn loc f =
allocaBytes (#size PgfExn) $ \c_exn -> do
res <- f c_exn
ex_type <- (#peek PgfExn, type) c_exn :: IO (#type PgfExnType)
@@ -236,13 +239,13 @@ withPgfExn f =
mb_fpath <- if c_msg == nullPtr
then return Nothing
else fmap Just (peekCString c_msg)
ioError (errnoToIOError "readPGF" (Errno errno) Nothing mb_fpath)
ioError (errnoToIOError loc (Errno errno) Nothing mb_fpath)
(#const PGF_EXN_PGF_ERROR) -> do
c_msg <- (#peek PgfExn, msg) c_exn
msg <- peekCString c_msg
free c_msg
throwIO (PGFError msg)
_ -> throwIO (PGFError "An unidentified error occurred")
throwIO (PGFError loc msg)
_ -> throwIO (PGFError loc "An unidentified error occurred")
-----------------------------------------------------------------------
-- Marshalling

View File

@@ -75,7 +75,7 @@ branchPGF_ :: Ptr PgfText -> PGF -> Transaction a -> IO PGF
branchPGF_ c_name p (Transaction f) =
withForeignPtr (a_db p) $ \c_db ->
withForeignPtr (revision p) $ \c_revision ->
withPgfExn $ \c_exn ->
withPgfExn "branchPGF" $ \c_exn ->
mask $ \restore -> do
c_revision <- pgf_clone_revision c_db c_revision c_name c_exn
ex_type <- (#peek PgfExn, type) c_exn
@@ -103,7 +103,7 @@ checkoutPGF :: PGF -> String -> IO (Maybe PGF)
checkoutPGF p name =
withForeignPtr (a_db p) $ \c_db ->
withText name $ \c_name -> do
c_revision <- withPgfExn (pgf_checkout_revision c_db c_name)
c_revision <- withPgfExn "checkoutPGF" (pgf_checkout_revision c_db c_name)
if c_revision == nullPtr
then return Nothing
else do fptr2 <- C.newForeignPtr c_revision (withForeignPtr (a_db p) (\c_db -> pgf_free_revision c_db c_revision))