diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-07-08 11:02:43 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-09 08:47:22 -0400 |
commit | 2d4cdfda6a7f068fe4a1cf586ccb2866b35e0250 (patch) | |
tree | 9b308c925d387cada0126db89850a9820ab9307c /compiler/GHC.hs | |
parent | 60fabd7eb3e3450636673d818075da19074ddad0 (diff) | |
download | haskell-2d4cdfda6a7f068fe4a1cf586ccb2866b35e0250.tar.gz |
Avoid unsafePerformIO for getProgName
getProgName was used to append the name of the program (e.g. "ghc") to
printed error messages in the Show instance of GhcException. It doesn't
belong here as GHCi and GHC API users may want to override this behavior
by setting a different error handler. So we now call it in the
defaultErrorHandler instead.
Diffstat (limited to 'compiler/GHC.hs')
-rw-r--r-- | compiler/GHC.hs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/GHC.hs b/compiler/GHC.hs index ea1293f2a8..b7dd7dfd35 100644 --- a/compiler/GHC.hs +++ b/compiler/GHC.hs @@ -420,7 +420,7 @@ import Control.Monad.Catch as MC import GHC.Data.Maybe import System.IO.Error ( isDoesNotExistError ) -import System.Environment ( getEnv ) +import System.Environment ( getEnv, getProgName ) import System.Directory import Data.List (isPrefixOf) @@ -465,9 +465,13 @@ defaultErrorHandler fm (FlushOut flushOut) inner = (\ge -> liftIO $ do flushOut case ge of - Signal _ -> exitWith (ExitFailure 1) - _ -> do fm (show ge) - exitWith (ExitFailure 1) + Signal _ -> return () + ProgramError _ -> fm (show ge) + CmdLineError _ -> fm ("<command line>: " ++ show ge) + _ -> do + progName <- getProgName + fm (progName ++ ": " ++ show ge) + exitWith (ExitFailure 1) ) $ inner |