thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neil Jensen <neilcjen...@gmail.com>
Subject haskell and exceptions
Date Sat, 30 Jul 2011 23:33:44 GMT
Hello, I'm running into problems using the haskell interface to thrift, specifically with exceptions.

The server code below correctly returns results under normal operation; however, when I throw
an exception, either the client or the server is hanging.

instance IRRCalculator_Iface IRRCalculatorHandler where
    ping _ =
        print "ping()"

    portfolioIRR _ accounts enddate = do
        portirr <-  IRR.portfolioIRR accounts' enddate'
        case portirr of
            Nothing -> do
                print "no results found" 
                throw $ NoIRRresults { f_NoIRRresults_why = Just "No irr results"}
            Just x  -> do
                let (irrInfo,cfs') = fromJust portirr
                let cfs = map makeCashflow cfs'
                let irr' = makeIrr irrInfo cfs
                return irr'
        where accounts' = map (\x -> fromIntegral x) $ fromJust accounts
              enddate'  = fromIntegral $ fromJust enddate
 

Here is the client code that works:

main :: IO ()
main = do
    transport <- hOpen ("localhost", PortNumber port)
    let binProto = BinaryProtocol transport
    let client = (binProto, binProto)

    Client.ping client
    print "ping()"

    irr <- Client.portfolioIRR client [100042] 20110630
    print irr


Now when the client calls Client.portfolioIRR with arguments that will generate an exception,
I do see the 'no results found' in the server log, but the client hangs:

    E.catch (do irr' <- Client.portfolioIRR client [10042] 20110630
                   print irr'
                 )
               (print "error")

Interestingly, even in ghci if I do irr' <- Client.portfolioIRR client [10042] 20110630
it hangs... so, I'm not sure if the server is not properly sending the exception, or if the
client code is not dealing with it.

I haven't found any working examples of exception handling in haskell for Thrift... has anyone
got it working?

Thanks in advance,
Neil
Mime
View raw message