From 27cf6fbeeb19572a58a71ca7cf080aeea82d0cb8 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 27 Nov 2013 13:35:41 +0400 Subject: More informative ParamParseFailure --- src/Network/BitTorrent/Tracker/Message.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/Network/BitTorrent/Tracker') diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 53d7a946..3447a367 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs @@ -155,7 +155,7 @@ data AnnounceQuery = AnnounceQuery -- | If not specified, the request is regular periodic request. , reqEvent :: Maybe Event - } deriving (Show, Typeable) + } deriving (Show, Eq, Typeable) $(deriveJSON (L.map toLower . L.dropWhile isLower) ''AnnounceQuery) @@ -233,8 +233,9 @@ data QueryParam deriving (Show, Eq, Ord, Enum) data ParamParseFailure - = Missing QueryParam -- ^ param not found in query string; - | Invalid QueryParam -- ^ param present but not valid. + = Missing QueryParam -- ^ param not found in query string; + | Invalid QueryParam Text -- ^ param present but not valid. + deriving (Show, Eq) type ParamResult = Either ParamParseFailure @@ -271,11 +272,11 @@ parseAnnounceQuery params = AnnounceQuery where withError e = maybe (Left e) Right reqParam param p = withError (Missing param) . L.lookup (paramName param) - >=> withError (Invalid param) . p + >=> \x -> withError (Invalid param x) (p x) optParam param p ps | Just x <- L.lookup (paramName param) ps - = pure <$> withError (Invalid param) (p x) + = pure <$> withError (Invalid param x) (p x) | otherwise = pure Nothing progress = undefined @@ -426,8 +427,8 @@ invalidOffset = 150 -- -- paramFailureCode :: ParamParseFailure -> Int -paramFailureCode (Missing param) = missingOffset + fromEnum param -paramFailureCode (Invalid param) = invalidOffset + fromEnum param +paramFailureCode (Missing param ) = missingOffset + fromEnum param +paramFailureCode (Invalid param _) = invalidOffset + fromEnum param {----------------------------------------------------------------------- Scrape message -- cgit v1.2.3