Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TraceNodeIsLeader JSON parser #4187

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cardano-testnet/src/Test/Assert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module Test.Assert
, getRelevantLeaderSlots
) where

import Control.Applicative ((<*>))
import Control.Monad (Monad (..))
import Control.Monad (Monad (..), fail)
import Control.Monad.IO.Class (MonadIO)
import Control.Monad.Trans.Reader (ReaderT)
import Control.Monad.Trans.Resource (ResourceT)
Expand Down Expand Up @@ -86,10 +85,11 @@ data TraceNodeIsLeader = TraceNodeIsLeader
} deriving (Eq, Show)

instance FromJSON TraceNodeIsLeader where
parseJSON = Aeson.withObject "TraceNodeIsLeader" $ \v ->
TraceNodeIsLeader
<$> v .: "kind"
<*> v .: "slot"
parseJSON = Aeson.withObject "TraceNodeIsLeader" $ \v -> do
k <- v .: "val" >>= (.: "kind")
if k == "TraceNodeIsLeader"
then TraceNodeIsLeader k <$> (v .: "val" >>= (.: "slot"))
else fail "Not the right kind"
Copy link
Contributor

@Jimbo4350 Jimbo4350 Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasagredo @newhoggy What is the failure "Not the right kind" going to indicate to the user? What is not the right kind? The error message says pretty much nothing.

@jasagredo can you improve this message to something like "Expected kind TraceNodeIsLeader but got: " <> k

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. This is only used in tests though, but yeah, a more informative error message would be better.


instance FromJSON Kind where
parseJSON = Aeson.withObject "Kind" $ \v ->
Expand Down