[Git][ghc/ghc][wip/T27456] base: Display ExceptionContext in WhileHandling's textual description
sheaf pushed to branch wip/T27456 at Glasgow Haskell Compiler / GHC Commits: c851b007 by Ben Gamari at 2026-07-03T12:24:34+02:00 base: Display ExceptionContext in WhileHandling's textual description As originally-implemented the implementation for `WhileHandling(displayExceptionAnnotation)` would display the `ExceptionContext` of the exception which it carries (as this was the behavior of `displayException`, in terms of which `displayExceptionAnnotation` was implemented). However, in 284ffab3 the definition of `SomeException(displayException)` was changed to exclude the `ExceptionContext`. This means that `WhileHandling(displayExceptionAnnotation)` fails to describe the provenance of the exception which it captures, greatly limiting its utility. Return the implementation to its originally-specified behavior by implementing `WhileHandling(displayExceptionAnnotation)` in terms of `displayExceptionWithInfo`. Fixes #27456. - - - - - 9 changed files: - + changelog.d/T27456 - libraries/base/changelog.md - libraries/base/tests/T15349.stderr - libraries/ghc-internal/src/GHC/Internal/Exception/Type.hs - libraries/ghc-internal/tests/backtraces/T14532b.stdout - testsuite/tests/codeGen/should_run/cgrun025.stderr - testsuite/tests/exceptions/T26759.stderr - testsuite/tests/ghc-e/should_fail/T18441fail7.stderr - testsuite/tests/mdo/should_fail/mdofail006.stderr Changes: ===================================== changelog.d/T27456 ===================================== @@ -0,0 +1,8 @@ +section: base +issues: #27456 +mrs: ! +synopsis: + Show `ExceptionContext` in `displayExceptionAnnotation` implementation of `WhileHandling` +description: + In the past ``displayException`` (in terms of which ``WhileHandling``\'s ``displayExceptionAnnotation` is implemented) was changed to hide ``ExceptionContext``. This regressed the behavior of ``displayExceptionAnnotation`` from that which was originally specified. Restore the intended behavior of showing the ``ExceptionContext`` of the carried exception. + ===================================== libraries/base/changelog.md ===================================== @@ -31,6 +31,7 @@ * Export `labelThread` from `Control.Concurrent`.([CLC proposal #376](https://github.com/haskell/core-libraries-committee/issues/376)) * Add a new module `System.IO.OS` with operations for obtaining operating-system handles (file descriptors, Windows handles). ([CLC proposal #369](https://github.com/haskell/core-libraries-committee/issues/369)) * Evaluate backtraces for "error" exceptions at the moment they are thrown. ([CLC proposal #383](https://github.com/haskell/core-libraries-committee/issues/383)) + * Show `ExceptionContext` in `displayExceptionAnnotation` implementation of `WhileHandling` ([GHC #27456](https://gitlab.haskell.org/ghc/ghc/-/issues/27456)) * Hide implementation details when throwing exceptions in throw and throwSTM. ([CLC proposal #387](https://github.com/haskell/core-libraries-committee/issues/387)) * Change `hIsReadable` and `hIsWritable` such that they always throw a respective exception when encountering a closed or semi-closed handle, not just in the case of a file handle. ([CLC proposal #371](github.com/haskell/core-libraries-committee/issues/371)) * Annotate `onException` continuation with `WhileHandling`. ([CLC Proposal #397](https://github.com/haskell/core-libraries-committee/issues/397)) ===================================== libraries/base/tests/T15349.stderr ===================================== @@ -1,9 +1,11 @@ -T15349: Uncaught exception ghc-internal:GHC.Internal.Control.Exception.Base.NonTermination: +T15349.exe: Uncaught exception ghc-internal:GHC.Internal.Control.Exception.Base.NonTermination: <<loop>> -While handling thread blocked indefinitely in an MVar operation +While handling ghc-internal:GHC.Internal.IO.Exception.BlockedIndefinitelyOnMVar: + | + | thread blocked indefinitely in an MVar operation HasCallStack backtrace: - throwIO, called at libraries/ghc-internal/src/GHC/Internal/Control/Monad/ST/Imp.hs:58:37 in ghc-internal:GHC.Internal.Control.Monad.ST.Imp + throwIO, called at libraries\ghc-internal\src\GHC\Internal\Control\Monad\ST\Imp.hs:59:37 in ghc-internal:GHC.Internal.Control.Monad.ST.Imp ===================================== libraries/ghc-internal/src/GHC/Internal/Exception/Type.hs ===================================== @@ -84,7 +84,7 @@ data WhileHandling = WhileHandling SomeException deriving Show instance ExceptionAnnotation WhileHandling where displayExceptionAnnotation (WhileHandling e) = - "While handling " ++ case lines $ displayException e of + "While handling " ++ case lines $ displayExceptionWithInfo e of [] -> "" (l1:ls) -> -- Indent lines forward. ===================================== libraries/ghc-internal/tests/backtraces/T14532b.stdout ===================================== @@ -2,7 +2,14 @@ ghc-internal:GHC.Internal.Exception.ErrorCall: Error in Exception Handler -While handling Main Error +While handling ghc-internal:GHC.Internal.Exception.ErrorCall: + | + | Main Error + | + | My custom Backtraces: + | HasCallStack backtrace: + | throwIO, called at T14532b.hs:32:6 in main:Main + | My custom Backtraces: HasCallStack backtrace: @@ -13,7 +20,14 @@ ghc-internal:GHC.Internal.Exception.ErrorCall: Error in Exception Handler -While handling Main Error +While handling ghc-internal:GHC.Internal.Exception.ErrorCall: + | + | Main Error + | + | My custom Backtraces: + | HasCallStack backtrace: + | error, called at T14532b.hs:41:6 in main:Main + | My custom Backtraces: HasCallStack backtrace: ===================================== testsuite/tests/codeGen/should_run/cgrun025.stderr ===================================== @@ -1,4 +1,4 @@ -"cgrun025" +"cgrun025.exe" ["cgrun025.hs"] GOT PATH {-# LANGUAGE ScopedTypeVariables #-} @@ -27,11 +27,16 @@ main = do trace "hello, trace" $ catch (getEnv "__WURBLE__" >> return ()) (\ (e :: SomeException) -> error "hello, error") hello, trace -cgrun025: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall: +cgrun025.exe: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall: hello, error -While handling __WURBLE__: getEnv: does not exist (no environment variable) +While handling ghc-internal:GHC.Internal.IO.Exception.IOException: + | + | __WURBLE__: getEnv: does not exist (no environment variable) + | + | HasCallStack backtrace: + | ioException, called at libraries\ghc-internal\src\GHC\Internal\System\Environment.hs:204:26 in ghc-internal:GHC.Internal.System.Environment HasCallStack backtrace: error, called at cgrun025.hs:25:75 in main:Main ===================================== testsuite/tests/exceptions/T26759.stderr ===================================== @@ -1,8 +1,13 @@ -T26759: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall: +T26759.exe: Uncaught exception ghc-internal:GHC.Internal.Exception.ErrorCall: cleanup failure -While handling outer failure +While handling ghc-internal:GHC.Internal.Exception.ErrorCall: + | + | outer failure + | + | HasCallStack backtrace: + | throwIO, called at T26759.hs:6:21 in main:Main HasCallStack backtrace: throwIO, called at T26759.hs:7:22 in main:Main ===================================== testsuite/tests/ghc-e/should_fail/T18441fail7.stderr ===================================== @@ -1,10 +1,12 @@ -<interactive>: Uncaught exception ghc-9.13-inplace:GHC.Utils.Panic.GhcException: +<interactive>: Uncaught exception ghc-10.1-inplace:GHC.Utils.Panic.GhcException: IO error: "Abcde" does not exist -While handling IO error: "Abcde" does not exist +While handling ghc-10.1-inplace:GHC.Utils.Panic.GhcException: + | + | IO error: "Abcde" does not exist HasCallStack backtrace: - throwIO, called at compiler/GHC/Utils/Error.hs:512:19 in ghc-9.13-inplace:GHC.Utils.Error + throwIO, called at compiler\GHC\Utils\Error.hs:499:19 in ghc-10.1-inplace:GHC.Utils.Error 1 ===================================== testsuite/tests/mdo/should_fail/mdofail006.stderr ===================================== @@ -1,9 +1,11 @@ -mdofail006: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.FixIOException: +mdofail006.exe: Uncaught exception ghc-internal:GHC.Internal.IO.Exception.FixIOException: cyclic evaluation in fixIO -While handling thread blocked indefinitely in an MVar operation +While handling ghc-internal:GHC.Internal.IO.Exception.BlockedIndefinitelyOnMVar: + | + | thread blocked indefinitely in an MVar operation HasCallStack backtrace: - throwIO, called at libraries/ghc-internal/src/GHC/Internal/Control/Monad/Fix.hs:167:37 in ghc-internal:GHC.Internal.Control.Monad.Fix + throwIO, called at libraries\ghc-internal\src\GHC\Internal\Control\Monad\Fix.hs:169:37 in ghc-internal:GHC.Internal.Control.Monad.Fix View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c851b007239b9f6b4a97c3dfe5679dc2... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c851b007239b9f6b4a97c3dfe5679dc2... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
sheaf (@sheaf)