never executed always true always false
    1 module Core.Control.Error (handleError) where
    2 
    3 import Control.Monad.Except (ExceptT, runExceptT)
    4 
    5 -- | Run an 'ExceptT' computation and handle the error case.
    6 --
    7 -- Similar to Rust's @unwrap_or_else@, this extracts the value from an 'ExceptT'
    8 -- computation, calling the provided handler if the computation fails.
    9 --
   10 -- Example:
   11 --
   12 -- @
   13 -- main :: IO ()
   14 -- main = do
   15 --   args <- getArgs
   16 --   run args \`handleError\` die
   17 -- @
   18 handleError :: (Monad m) => ExceptT e m a -> (e -> m a) -> m a
   19 handleError action handler = runExceptT action >>= either handler pure