Simon Jakobi pushed to branch wip/sjakobi/T27847-ghci-rethrow-backtrace at Glasgow Haskell Compiler / GHC
Commits:
-
b5957144
by Simon Jakobi at 2026-09-25T01:11:21+02:00
5 changed files:
- compiler/GHC/Utils/Exception.hs
- ghc/GHCi/UI.hs
- libraries/ghci/GHCi/Message.hs
- testsuite/tests/ghc-e/should_fail/T18441fail7.stderr
- testsuite/tests/ghc-e/should_run/ghc-e005.stderr
Changes:
| ... | ... | @@ -11,6 +11,7 @@ import GHC.Prelude.Basic |
| 11 | 11 | |
| 12 | 12 | import GHC.IO (catchException)
|
| 13 | 13 | import Control.Exception as CE hiding (assert)
|
| 14 | +import Control.Exception.Context (emptyExceptionContext)
|
|
| 14 | 15 | import Control.Monad.IO.Class
|
| 15 | 16 | import Control.Monad.Catch
|
| 16 | 17 | |
| ... | ... | @@ -24,4 +25,8 @@ handleIO = flip catchIO |
| 24 | 25 | tryIO :: IO a -> IO (Either IOException a)
|
| 25 | 26 | tryIO = CE.try
|
| 26 | 27 | |
| 28 | +-- | Remove the context, such as backtraces and annotations, from an exception.
|
|
| 29 | +dropExceptionContext :: SomeException -> SomeException
|
|
| 30 | +dropExceptionContext e = toException (ExceptionWithContext emptyExceptionContext e)
|
|
| 31 | + |
|
| 27 | 32 | type ExceptionMonad m = (MonadCatch m, MonadThrow m, MonadMask m, MonadIO m) |
| ... | ... | @@ -1079,8 +1079,12 @@ runGHCi paths maybe_exprs = do |
| 1079 | 1079 | -- current progname in the exception text:
|
| 1080 | 1080 | -- <progname>: <exception>
|
| 1081 | 1081 | liftIO $ withProgName (progname st)
|
| 1082 | - $ topHandler e
|
|
| 1083 | 1082 | -- this used to be topHandlerFastExit, see #2228
|
| 1083 | + $ topHandler
|
|
| 1084 | + -- The program's own context is already part of the
|
|
| 1085 | + -- message (see toSerializableException). The rest
|
|
| 1086 | + -- comes from GHC itself (#27847).
|
|
| 1087 | + $ dropExceptionContext e
|
|
| 1084 | 1088 | runInputTWithPrefs defaultPrefs defaultSettings $ do
|
| 1085 | 1089 | -- make `ghc -e` exit nonzero on failure, see #7962, #9916, #17560, #18441
|
| 1086 | 1090 | _ <- runCommands' hdle
|
| ... | ... | @@ -466,8 +466,7 @@ data LoadedDLL |
| 466 | 466 | -- * UserInterrupt has a special meaning
|
| 467 | 467 | -- * In ghc -e, exitWith should exit with the appropriate exit code
|
| 468 | 468 | --
|
| 469 | --- So all we need to do is distinguish UserInterrupt and ExitCode, and
|
|
| 470 | --- all other exceptions can be represented by their 'show' string.
|
|
| 469 | +-- So all we need to do is distinguish UserInterrupt and ExitCode.
|
|
| 471 | 470 | --
|
| 472 | 471 | data SerializableException
|
| 473 | 472 | = EUserInterrupt
|
| 1 | 1 | <interactive>: Uncaught exception ghc-10.1-inplace:GHC.Utils.Panic.GhcException:
|
| 2 | 2 | |
| 3 | 3 | IO error: "Abcde" does not exist
|
| 4 | - |
|
| 5 | -While handling ghc-10.1-inplace:GHC.Utils.Panic.GhcException:
|
|
| 6 | - |
|
|
| 7 | - | IO error: "Abcde" does not exist
|
|
| 8 | - |
|
|
| 9 | - | HasCallStack backtrace:
|
|
| 10 | - | throw, called at compiler/GHC/Utils/Panic.hs:180:21 in ghc-10.1-inplace:GHC.Utils.Panic
|
|
| 11 | - | throwGhcException, called at ghc/GHCi/UI.hs:2851:21 in ghc-bin-10.1.20260801-inplace:GHCi.UI
|
|
| 12 | - |
|
| 13 | -HasCallStack backtrace:
|
|
| 14 | - throwIO, called at compiler/GHC/Utils/Error.hs:513:19 in ghc-10.1-inplace:GHC.Utils.Error
|
|
| 15 | - |
|
| 16 | 4 | 1 |
| ... | ... | @@ -4,8 +4,3 @@ foo |
| 4 | 4 | |
| 5 | 5 | HasCallStack backtrace:
|
| 6 | 6 | error, called at ghc-e005.hs:12:10 in main:Main |
| 7 | - |
|
| 8 | - |
|
| 9 | -HasCallStack backtrace:
|
|
| 10 | - throwIO, called at ghc\GHCi\UI.hs:1655:31 in ghc-bin-10.1.20260629-inplace:GHCi.UI
|
|
| 11 | - |