mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-12-25 18:13:52 +03:00
f06c933182
fix
25 lines
846 B
Haskell
25 lines
846 B
Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
|
module Command
|
|
( Command
|
|
, runCommand
|
|
, CommandError(..)
|
|
) where
|
|
|
|
import Control.Monad.Except (ExceptT, MonadError, runExceptT)
|
|
import Control.Monad.IO.Class (MonadIO)
|
|
|
|
|
|
newtype Command a = Command { _runCommand :: ExceptT CommandError IO a }
|
|
deriving (Functor, Applicative, Monad, MonadIO, MonadError CommandError)
|
|
|
|
runCommand :: Command a -> IO ()
|
|
runCommand cmd = do
|
|
errorOrResult <- runExceptT $ _runCommand cmd
|
|
case errorOrResult of
|
|
Left cmdError -> putStrLn $ "Error: " ++ _errorMsg cmdError
|
|
Right _ -> return ()
|
|
|
|
-- TODO: What if we want to recognize errors in order to handle them?
|
|
-- Should we add _commandErrorType? Should CommandError be parametrized by it, is that even possible?
|
|
data CommandError = CommandError { _errorMsg :: !String }
|