Skip to content

Commit

Permalink
Updated to use Control.Monad.Error as haxr switched to it.
Browse files Browse the repository at this point in the history
  • Loading branch information
megantti committed Mar 16, 2015
1 parent fdff432 commit 1a41cb3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Network/RTorrent/Command/Internals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Network.RTorrent.Command.Internals (

import Control.Applicative
import Control.DeepSeq
import Control.Monad.Error
import Control.Monad.Except
import Control.Monad.Identity

import qualified Codec.Binary.UTF8.String as U
Expand Down Expand Up @@ -95,7 +95,7 @@ single v@(ValueStruct vars) = maybe
single v = fail $ "Failed to match a singleton array, got: " ++ show v

parseValue :: (Monad m, XmlRpcType a) => Value -> m a
parseValue = fromRight . runIdentity . runErrorT . fromValue
parseValue = fromRight . runIdentity . runExceptT . fromValue
where
fromRight (Right r) = return r
fromRight (Left e) = fail $ "parseValue failed: " ++ e
Expand Down
12 changes: 6 additions & 6 deletions Network/RTorrent/RPC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Network.RTorrent.RPC (
, callRTorrent
) where

import Control.Monad.Error (ErrorT(..), throwError, strMsg)
import Control.Monad.Except (ExceptT(..), throwError, runExceptT)
import Control.Exception
import Data.Monoid
import qualified Data.ByteString as BS
Expand All @@ -111,17 +111,17 @@ import qualified Network.RTorrent.Command.Internals as C
import Network.RTorrent.CommandList
import Network.RTorrent.SCGI

callRTorrentRaw :: HostName -> Int -> C.RTMethodCall -> ErrorT String IO Value
callRTorrentRaw :: HostName -> Int -> C.RTMethodCall -> ExceptT String IO Value
callRTorrentRaw host port calls = do
let request = Body [] . mconcat . LB.toChunks $ renderCall call
Body _ content <- ErrorT $ query host port request
Body _ content <- ExceptT $ query host port request
let cs = map (toEnum . fromEnum) $ BS.unpack content
response <- parseResponse cs
case response of
Return ret -> case ret of
ValueArray arr -> return $ ValueArray arr
val -> throwError . strMsg $ "Got value of type " ++ show (getType val)
Fault code err -> throwError . strMsg $ show code ++ ": " ++ err
val -> throwError $ "Got value of type " ++ show (getType val)
Fault code err -> throwError $ show code ++ ": " ++ err
where
call = MethodCall "system.multicall" [C.runRTMethodCall calls]

Expand All @@ -134,7 +134,7 @@ callRTorrent :: Command a =>
-> a
-> IO (Either String (Ret a))
callRTorrent host port command =
(runErrorT $ do
(runExceptT $ do
ret <- callRTorrentRaw host port (C.commandCall command)
C.commandValue command ret)
`catches` [ Handler (\e -> return . Left $ show (e :: IOException))
Expand Down
2 changes: 1 addition & 1 deletion rtorrent-rpc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library
mtl >=2.1 && <2.3,
bytestring >=0.10 && <0.11 ,
network >=2.6,
haxr >=3000.10.3.1 && <3000.11,
haxr >=3000.10.4.2 && <3000.10.5,
blaze-builder >=0.3 && <0.4,
blaze-textual >=0.2 && <0.3,
attoparsec >=0.12 && <0.13,
Expand Down

0 comments on commit 1a41cb3

Please sign in to comment.