Couldn't match type `IOException` with `RequestError`
kendricktan opened this issue · comments
Kendrick Tan commented
I'm just trying to make a very simple 'EchoBot' that echos whatever the input query is. E.g.
/echo hello
. Bot replies with hello
.
However, I'm having some trouble replying to the user, I'm getting this error on compile:
• Couldn't match type ‘IOException’ with ‘RequestError’
arising from a functional dependency between:
constraint ‘Control.Monad.Error.Class.MonadError RequestError IO’
arising from a use of ‘say’
instance ‘Control.Monad.Error.Class.MonadError IOException IO’
at <no location info>
• In the first argument of ‘void’, namely ‘(say m config)’
In a stmt of a 'do' block: void (say m config)
In the expression:
do { putStrLn ("+ Outgoing message: " <> show (encode m));
void (say m config);
return "" }
Code:
testTo :: Command -> IO Text
testTo cmd = do
putStrLn ("+ Incoming command: " <> show cmd)
config <- slackConfig
message <- runExceptT (messageOfCommand cmd)
case (debug, message) of
(False, Right m) -> do
putStrLn ("+ Outgoing message: " <> show (encode m))
void (say m config) -- <<< Error occurs here
return ""
(False, Left e) ->
return ("popslave encountered an error " <> (e ^. packed))
(True, Right m) -> do
putStrLn ("+ Outgoing message: " <> show (encode m))
return ""
(True, Left e) -> do
putStrLn ("+ Outgoing ERROR: " <> e)
return ""
where
debug = False
Any help would be appreciated.
Kendrick Tan commented
Solved it, credits to @TRManderson
testTo :: Command -> IO Text
testTo cmd = do
putStrLn ("+ Incoming command: " <> show cmd)
config <- slackConfig
message <- runExceptT (messageOfCommand cmd)
case (debug, message) of
(False, Right m) -> do
putStrLn ("+ Outgoing message: " <> show (encode m))
eitherResult <- runExceptT $ say m config
case eitherResult of
(Left e) -> return "error"
(Right _) -> return ""
return ""
(False, Left e) ->
return ("popslave encountered an error " <> (e ^. packed))
(True, Right m) -> do
putStrLn ("+ Outgoing message: " <> show (encode m))
return ""
(True, Left e) -> do
putStrLn ("+ Outgoing ERROR: " <> e)
return ""
where debug = False