{-# LANGUAGE CPP #-}

module Mikan.Utils.CallStack.Exception
  ( showIOException
  ) where

import Control.Exception

import Mikan.Utils.List (dropFrom)
import Mikan.Utils.String (rtrim)

--------------------------------------------------------------------------------
-- Exceptions

-- | Print an 'IOException' without the call stack.
showIOException :: Exception e => e -> String
showIOException :: forall e. Exception e => e -> String
showIOException =
  String -> String
rtrim
#if MIN_VERSION_base(4,20,0)
  -- Andreas, 2024-07-05, issue #7299.
  -- Ugly hack to drop call stack (introduced in GHC 9.10) from IOException.
  -- If you have a better solution, please update this.
  (String -> String) -> (e -> String) -> e -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List1 Char -> String -> String
forall a. Eq a => List1 a -> [a] -> [a]
dropFrom List1 Char
"HasCallStack"
#endif
  (String -> String) -> (e -> String) -> e -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> String
forall e. Exception e => e -> String
displayException