Skip to content

exception callstack is printed multiple times

Hi,

I am trying to reason GHC exception stack trace and I cannot explain why stack trace is printed multiple times:

Sample 1

main :: IO ()
main = do
  s <- readFile "/x"
  putStrLn s
$ stack run --profile --resolver=ghc-9.0.1  -- +RTS  -xc
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: 
  Main.main
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: 
  Main.main
*** Exception (reporting due to +RTS -xc): (THUNK_2_0), stack trace: 
  Main.main
magic-exceptions-exe: /x: openFile: does not exist (No such file or directory)

Sample 2

import System.Posix.Files
main :: IO ()
main = do  
  _ <- getFileStatus "/x"
  pure ()
$ stack run --profile --resolver=ghc-9.0.1  -- +RTS  -xc
*** Exception (reporting due to +RTS -xc): (THUNK), stack trace: 
  Main.main
*** Exception (reporting due to +RTS -xc): (THUNK), stack trace: 
  Main.main
magic-exceptions-exe: /x: getFileStatus: does not exist (No such file or directory)

Sample 1 gives 3 exceptions while sample 2 gives 2 exceptions. What is the difference between them? I think in both cases 1 exception should be printed.

Same behavior I observed with ghc-8.10.7

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information