summaryrefslogtreecommitdiff
path: root/Remote
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-12-08 15:47:49 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-12-08 15:47:49 -0400
commitfaa56834d282c6bb9b3338ed7514f2e0665d166f (patch)
treec68477884041f5faa7ceb775cd79830ad48a5f5a /Remote
parent1e7d212d4c0112e5b6b4872d84934fc85aa70315 (diff)
convert P2P runners from Maybe to Either String
So we get some useful error messages when things fail. This commit was sponsored by Peter Hogg on Patreon.
Diffstat (limited to 'Remote')
-rw-r--r--Remote/P2P.hs25
1 files changed, 15 insertions, 10 deletions
diff --git a/Remote/P2P.hs b/Remote/P2P.hs
index 1d7ede30f..bc0e2f923 100644
--- a/Remote/P2P.hs
+++ b/Remote/P2P.hs
@@ -127,14 +127,15 @@ runProto u addr connpool a = withConnection u addr connpool (runProto' a)
runProto' :: P2P.Proto a -> Connection -> Annex (Connection, Maybe a)
runProto' _ ClosedConnection = return (ClosedConnection, Nothing)
runProto' a (OpenConnection conn) = do
- r <- runFullProto Client conn a
+ v <- runFullProto Client conn a
-- When runFullProto fails, the connection is no longer usable,
-- so close it.
- if isJust r
- then return (OpenConnection conn, r)
- else do
+ case v of
+ Left e -> do
+ warning e
liftIO $ closeConnection conn
- return (ClosedConnection, r)
+ return (ClosedConnection, Nothing)
+ Right r -> return (OpenConnection conn, Just r)
-- Uses an open connection if one is available in the ConnectionPool;
-- otherwise opens a new connection.
@@ -176,16 +177,20 @@ openConnection u addr = do
res <- liftIO $ runNetProto conn $
P2P.auth myuuid authtoken
case res of
- Just (Just theiruuid)
+ Right (Just theiruuid)
| u == theiruuid -> return (OpenConnection conn)
| otherwise -> do
liftIO $ closeConnection conn
warning "Remote peer uuid seems to have changed."
return ClosedConnection
- _ -> do
- liftIO $ closeConnection conn
+ Right Nothing -> do
warning "Unable to authenticate with peer."
+ liftIO $ closeConnection conn
+ return ClosedConnection
+ Left e -> do
+ warning e
+ liftIO $ closeConnection conn
return ClosedConnection
- Left _e -> do
- warning "Unable to connect to peer."
+ Left e -> do
+ warning $ "Unable to connect to peer. (" ++ show e ++ ")"
return ClosedConnection