diff options
author | Ben Gamari <ben@smart-cactus.org> | 2017-10-19 13:25:51 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-10-19 16:43:24 -0400 |
commit | afc04b2689e5b936ecc8689c194a0ed2c0a2e6da (patch) | |
tree | 5a7406b1a01ee898f22a7e498d471e3bde391b6d /compiler/utils/Outputable.hs | |
parent | 2ca8cf69c50f6fcae17fdcbbcad16227519e5d02 (diff) | |
download | haskell-afc04b2689e5b936ecc8689c194a0ed2c0a2e6da.tar.gz |
Outputable: Add pprTraceException
Diffstat (limited to 'compiler/utils/Outputable.hs')
-rw-r--r-- | compiler/utils/Outputable.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index c79cbc5551..95960f59b0 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -81,8 +81,9 @@ module Outputable ( -- * Error handling and debugging utilities pprPanic, pprSorry, assertPprPanic, pprPgmError, pprTrace, pprTraceDebug, pprTraceIt, warnPprTrace, pprSTrace, + pprTraceException, trace, pgmError, panic, sorry, assertPanic, - pprDebugAndThen, callStackDoc + pprDebugAndThen, callStackDoc, ) where import GhcPrelude @@ -126,6 +127,8 @@ import Data.List (intersperse) import GHC.Fingerprint import GHC.Show ( showMultiLineString ) import GHC.Stack ( callStack, prettyCallStack ) +import Control.Monad.IO.Class +import Exception {- ************************************************************************ @@ -1168,6 +1171,13 @@ pprTrace str doc x pprTraceIt :: Outputable a => String -> a -> a pprTraceIt desc x = pprTrace desc (ppr x) x +-- | @pprTraceException desc x action@ runs action, printing a message +-- if it throws an exception. +pprTraceException :: ExceptionMonad m => String -> SDoc -> m a -> m a +pprTraceException heading doc = + handleGhcException $ \exc -> liftIO $ do + putStrLn $ showSDocDump unsafeGlobalDynFlags (sep [text heading, nest 2 doc]) + throwGhcExceptionIO exc -- | If debug output is on, show some 'SDoc' on the screen along -- with a call stack when available. |