Skip to content

Commit

Permalink
Make listPoolLifeCycleData log parse failures.
Browse files Browse the repository at this point in the history
For rows that fail to parse: we create a log entry for each error.
For rows that parse successfully: we return these as part of the result.

In response to review feedback:

#2111 (comment)
  • Loading branch information
jonathanknowles committed Sep 8, 2020
1 parent 9708fd4 commit 68aaf9e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/core/src/Cardano/Pool/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import Control.Monad.Trans.Except
import Control.Tracer
( Tracer (..), contramap, natTracer, traceWith )
import Data.Either
( rights )
( lefts, rights )
import Data.Function
( (&) )
import Data.Functor
Expand Down Expand Up @@ -385,14 +385,19 @@ newDBLayer trace fp timeInterpreter = do
<*> fromPersistValue retirementEpoch
rights . fmap safeCast <$> rawSql query parameters

listPoolLifeCycleData epochNo =
rights . fmap parseRow <$> rawSql query parameters
listPoolLifeCycleData epochNo = do
parsedRows <- fmap parseRow <$> rawSql query parameters
mapM_ onParseFailure $ lefts parsedRows
pure $ rights parsedRows
where
query = T.unwords
[ "SELECT *"
, "FROM active_pool_lifecycle_data"
, "WHERE retirement_epoch IS NULL OR retirement_epoch > ?;"
]
onParseFailure e =
liftIO $ traceWith trace $ MsgParseFailure $ T.unwords
["listPoolLifeCycleData:", e]
parameters = [ toPersistValue epochNo ]
parseRow
( Single fieldPoolId
Expand Down

0 comments on commit 68aaf9e

Please sign in to comment.