summaryrefslogtreecommitdiff
path: root/compiler/GHC.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-07-08 11:02:43 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-09 08:47:22 -0400
commit2d4cdfda6a7f068fe4a1cf586ccb2866b35e0250 (patch)
tree9b308c925d387cada0126db89850a9820ab9307c /compiler/GHC.hs
parent60fabd7eb3e3450636673d818075da19074ddad0 (diff)
downloadhaskell-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.hs12
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