I propose this interdiff:
diff --git a/src/Ganeti/THH/RPC.hs b/src/Ganeti/THH/RPC.hs
index 35342d4..f0894a4 100644
--- a/src/Ganeti/THH/RPC.hs
+++ b/src/Ganeti/THH/RPC.hs
@@ -69,6 +69,9 @@ dispatch fs =
, US.hExec = liftToHandler . exec
}
where
+ orError :: (MonadError e m, Error e) => Maybe a -> e -> m a
+ orError m e = maybe (throwError e) return m
+
exec (Request m as) = do
(RpcFn f) <- orError (Map.lookup m fs)
(strMsg $ "No such method: " ++ m)
@@ -81,9 +84,6 @@ dispatch fs =
-> US.HandlerResult m J.JSValue
liftToHandler = liftM ((,) True) . runResultT
- orError :: (MonadError e m, Error e) => Maybe a -> e -> m a
- orError m e = maybe (throwError e) return m
-
-- | Converts a function into the appropriate @RpcFn m@ expression.
-- The function's result must be monadic.
toRpcFn :: Name -> Q Exp
On Thu, Feb 13, 2014 at 3:35 PM, Klaus Aehlig <[email protected]> wrote:
> On Thu, Feb 13, 2014 at 02:19:36PM +0100, Petr Pudlak wrote:
> > The main function in this module takes a list of names of functions and
> > uses TH to create a RPC server, represented as a value of type Handler
>
> s/a RPC server/an RPC server/
>
> > (from Ganeti.UDSServer). This can be readily used to create a daemon
> > that dispatches RPC requests to the given functions.
> >
> > Signed-off-by: Petr Pudlak <[email protected]>
>
> > +dispatch :: (Monad m)
> > + => Map String (RpcFn (ResultT GanetiException m)) -> RpcServer
> m
> > +dispatch fs =
> > + US.Handler { US.hParse = decodeRequest
> > + , US.hInputLogShort = rMethod
> > + , US.hInputLogLong = show
> > + , US.hExec = liftToHandler . exec
> > + }
> > + where
> > + exec (Request m as) = do
> > + (RpcFn f) <- orError (Map.lookup m fs)
> > + (strMsg $ "No such method: " ++ m)
> > + i <- fromJResultE "RPC input" . J.readJSON $ as
> > + o <- f i -- lift $ f i
> > + return $ J.showJSON o
> > +
> > + liftToHandler :: (Monad m)
> > + => ResultT GanetiException m J.JSValue
> > + -> US.HandlerResult m J.JSValue
> > + liftToHandler = liftM ((,) True) . runResultT
> > +
> > + orError :: (MonadError e m, Error e) => Maybe a -> e -> m a
> > + orError m e = maybe (throwError e) return m
>
> Personally, I'm not a fan of "where". But when using it, consider
> at least sorting the expressions in the where clause in logical
> order (onError is used in exec).
>
> Other than that, LGTM (no need to resend). Thanks.
>
>
> --
> Klaus Aehlig
> Google Germany GmbH, Dienerstr. 12, 80331 Muenchen
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores
>