Should print all connection exceptions if connection fails
Closed this issue · 0 comments
jwiegley commented
In Internal.hs
, the following code tries all host/port combinations in series:
connect ((host, port) : rest) = do
ctx <- Conn.initConnectionContext
result <- CE.try (Conn.connectTo ctx $ Conn.ConnectionParams
{ Conn.connectionHostname = host
, Conn.connectionPort = port
, Conn.connectionUseSecure = tlsSettings
, Conn.connectionUseSocks = Nothing
})
either
(\(ex :: CE.SomeException) -> do
connect rest)
(return)
result
connect [] = CE.throwIO $ ConnectionClosedException $ "Could not connect to any of the provided brokers: " ++ show (coServers connOpts)
Since this swallows all exceptions without printing them, if there's a deeper problem involved, the only thing the user will see is "Cannot connect to ", with no clue as to why. In my case, it was because I was missing netbase
in my Ubuntu Docker image, so it wasn't a connection problem, but something much deeper (which the Exception clearly indicated).
I suggest capturing all these exceptions to a list, and if no connection is possible, print out the whole list, with each exception paired to the host/port that caused it.