From 7d0a9f4e021dd15463659a115610df6d60f973a0 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 27 Jul 2017 03:40:27 -0400 Subject: More verbose reporting of parse errors. --- Mainline.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Mainline.hs b/Mainline.hs index 921bea0f..93393c40 100644 --- a/Mainline.hs +++ b/Mainline.hs @@ -389,12 +389,21 @@ encodeAny tid key val aux = toDict $ .: "y" .=! key .: endDict +showParseError bs addr err = L8.unpack $ L8.unlines es + where + es = map (L8.append prefix) (L8.pack err : L8.lines pp) + + prefix = L8.pack (show addr) <> " --> " + + pp = either L8.pack showBEncode $ BE.decode bs + parsePacket :: ByteString -> SockAddr -> Either String (Message BValue, NodeInfo) -parsePacket bs addr = do pkt <- BE.decode bs - -- TODO: Error packets do not inclucde a valid msgOrigin. - -- The BE.decode method is using 'zeroID' as a placeholder. - ni <- nodeInfo (msgOrigin pkt) addr - return (pkt, ni) +parsePacket bs addr = left (showParseError bs addr) $ do + pkt <- BE.decode bs + -- TODO: Error packets do not inclucde a valid msgOrigin. + -- The BE.decode method is using 'zeroID' as a placeholder. + ni <- nodeInfo (msgOrigin pkt) addr + return (pkt, ni) encodePacket :: Message BValue -> NodeInfo -> (ByteString, SockAddr) encodePacket msg ni = ( toStrict $ BE.encode msg @@ -623,8 +632,7 @@ mainlineKademlia client committee var sched return $ do io1 >> io2 hPutStrLn stderr $ unwords - [ "Buckets: " - , show (transitionedTo tr) + [ show (transitionedTo tr) , show (transitioningNode tr) ] } -- cgit v1.2.3