Skip to content

Commit 294c3b9

Browse files
authored
Merge pull request #893 from IntersectMBO/coot/cardano-ping-misconfiguration
cardano-ping: report user friendly error on misconfiguration
2 parents 39af17e + 6ebdc97 commit 294c3b9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cardano-cli/src/Cardano/CLI/Commands/Ping.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Cardano.CLI.Commands.Ping
22
( EndPoint (..)
33
, PingCmd (..)
4+
, getConfigurationError
45
)
56
where
67

@@ -22,3 +23,16 @@ data PingCmd = PingCmd
2223
, pingOptsGetTip :: !Bool
2324
}
2425
deriving (Eq, Show)
26+
27+
getConfigurationError :: PingCmd -> Maybe String
28+
getConfigurationError
29+
PingCmd
30+
{ pingCmdEndPoint = endPoint
31+
, pingOptsGetTip = getTip
32+
, pingOptsHandshakeQuery = query
33+
} =
34+
case endPoint of
35+
UnixSockEndPoint{}
36+
| query || getTip -> Nothing
37+
| otherwise -> Just "Unix sockets only support queries for available versions or a tip."
38+
HostEndPoint{} -> Nothing

cardano-cli/src/Cardano/CLI/Run/Ping.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import qualified Control.Concurrent.Class.MonadSTM.Strict as STM
1818
import Control.Exception (SomeException)
1919
import Control.Monad (forM, unless)
2020
import Control.Monad.Class.MonadAsync (MonadAsync (async, wait, waitCatch))
21+
import Control.Monad.Except (throwError)
2122
import Control.Monad.Trans.Except (ExceptT)
2223
import Control.Monad.Trans.Except.Extra (left)
2324
import Control.Tracer (Tracer (..))
@@ -28,7 +29,9 @@ import qualified Network.Socket as Socket
2829
import qualified System.Exit as IO
2930
import qualified System.IO as IO
3031

31-
newtype PingClientCmdError = PingClientCmdError [(AddrInfo, SomeException)]
32+
data PingClientCmdError
33+
= PingClientCmdError [(AddrInfo, SomeException)]
34+
| PingClientMisconfigurationError String
3235

3336
maybeHostEndPoint :: EndPoint -> Maybe String
3437
maybeHostEndPoint = \case
@@ -58,6 +61,9 @@ pingClient stdout stderr cmd = CNP.pingClient stdout stderr opts
5861
}
5962

6063
runPingCmd :: PingCmd -> ExceptT PingClientCmdError IO ()
64+
runPingCmd options
65+
| Just err <- getConfigurationError options =
66+
throwError $ PingClientMisconfigurationError err
6167
runPingCmd options = do
6268
let hints = Socket.defaultHints{Socket.addrSocketType = Socket.Stream}
6369

@@ -120,3 +126,4 @@ runPingCmd options = do
120126
renderPingClientCmdError :: PingClientCmdError -> Doc ann
121127
renderPingClientCmdError = \case
122128
PingClientCmdError es -> mconcat $ List.intersperse "\n" $ pshow <$> es
129+
PingClientMisconfigurationError err -> pretty err

0 commit comments

Comments
 (0)