file-location 0.4.4 → 0.4.5
raw patch · 5 files changed
+18/−15 lines, 5 files
Files
- Control/Exception/FileLocation.hs +12/−12
- FileLocation.hs +2/−1
- file-location.cabal +1/−1
- test/file-location.shelltest +2/−1
- test/main.hs +1/−0
Control/Exception/FileLocation.hs view
@@ -1,13 +1,18 @@-{-# LANGUAGE TemplateHaskell #-}-module Control.Exception.FileLocation (thrwIO, thrwsIO) where+{-# LANGUAGE TemplateHaskell, DeriveDataTypeable #-}+module Control.Exception.FileLocation+ ( thrwIO+ , thrwsIO+ , reThrow+ ) where import Language.Haskell.TH.Syntax import FileLocation.LocationString (locationToString) import Control.Exception.Base hiding (throwIO)-import qualified Control.Exception as E+import qualified Control.Exception.Lifted as E import Control.Monad.IO.Class (MonadIO (liftIO))+import Data.Typeable (Typeable) throwIO :: (Exception e, MonadIO m) => e -> m a throwIO = liftIO . E.throwIO@@ -24,15 +29,11 @@ let locStr = locationToString loc [|(\_mkEx -> throwIO (_mkEx (locStr ++ " " ++ errMsg)))|] -{- usually want to make a located vesion of a function rather than use this.- - perhaps it could be used to quickly make a located version--- {-# LANGUAGE DeriveDataTypeable, ExistentialQuantification #-}--- import Data.Typeable (Typeable)-data ReThrownException = forall e. (Exception e, Show e) => ReThrownException String e- deriving (Typeable)+data ReThrownException = ReThrownException String E.SomeException+ deriving Typeable instance Show ReThrownException where- show (ReThrownException s e) = "ReThrownException: " ++ s ++ "\n" ++ show e+ show (ReThrownException s e) = "ReThrownException (" ++ s ++ "): " ++ show e instance Exception ReThrownException @@ -40,5 +41,4 @@ reThrow = do loc <- qLocation let locStr = locationToString loc- [|\risky -> E.catch risky (\e -> throwIO (ReThrownException locStr e))|]- -}+ [|E.handle (E.throwIO . ReThrownException locStr)|]
FileLocation.hs view
@@ -5,13 +5,14 @@ , debug, debugM, debugMsg, debugMsgIf, dbg, dbgMsg, trc, ltrace, ltraceM, strace , locationToString , thrwIO, thrwsIO+ , reThrow ) where import FileLocation.LocationString (locationToString) import Debug.FileLocation (debug, debugM, debugMsg, dbg, dbgMsg, trc, ltrace, ltraceM, strace) import Debug.Util (debugMsgIf)-import Control.Exception.FileLocation (thrwIO, thrwsIO)+import Control.Exception.FileLocation (thrwIO, thrwsIO, reThrow) import Debug.Trace (trace) import Language.Haskell.TH.Syntax import Language.Haskell.TH(varE)
file-location.cabal view
@@ -1,5 +1,5 @@ Name: file-location-Version: 0.4.4+Version: 0.4.5 Synopsis: common functions that show file location information Homepage: https://github.com/gregwebs/FileLocation.hs License: BSD3
test/file-location.shelltest view
@@ -7,6 +7,7 @@ Caught main:Main test/main.hs:27:4 fromJst: Nothing Caught main:Main test/main.hs:28:4 fromRht: Left: "Lefty" Caught Prelude.undefined+("Rethrow",ReThrownException (main:Main test/main.hs:30:3): foo) >>>2 TRACE: main:Main test/main.hs:22:84 trc DEBUG: debugMsgIf: [1,2,3]@@ -17,7 +18,7 @@ traceM: [1,2,3] DEBUG: [1,2,3] main:Main test/main.hs:29:3 undefined-main: main:Main test/main.hs:30:5 Oh no!+main: main:Main test/main.hs:31:5 Oh no! >>>= 1 rm ./test/main ./test/main.hi ./test/main.o
test/main.hs view
@@ -27,4 +27,5 @@ ($fromJst Nothing) `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeException)) ($fromRht (Left "Lefty")) `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeException)) $undef `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeException))+ $reThrow (error "foo") `catch` \e -> print ("Rethrow", e :: SomeException) $(err "Oh no!")