An attempt to fix #1962. I think the exception comes from ‘connect’ in ‘Network.Socket’. I doubt that the proposed error message is friendly enough. Ideas? Also, can ‘handleJust’ catch ‘IOException’s that are not related to http_proxy?
From 3a7dbb2391a9b1a262e79d9afecd0ca6a907ce2a Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov <nik...@karetnikov.org> Date: Sat, 26 Jul 2014 01:59:55 +0400 Subject: [PATCH] Print a more friendly message when http_proxy is down. --- cabal-install/Distribution/Client/HttpUtils.hs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cabal-install/Distribution/Client/HttpUtils.hs b/cabal-install/Distribution/Client/HttpUtils.hs index 51fae37..0886e7b 100644 --- a/cabal-install/Distribution/Client/HttpUtils.hs +++ b/cabal-install/Distribution/Client/HttpUtils.hs @@ -21,8 +21,10 @@ import Network.Browser , setOutHandler, setErrHandler, setProxy, setAuthorityGen, request) import Network.Stream ( Result, ConnError(..) ) +import Control.Exception + ( handleJust ) import Control.Monad - ( liftM ) + ( liftM, guard ) import qualified Data.ByteString.Lazy.Char8 as ByteString import Data.ByteString.Lazy (ByteString) @@ -42,6 +44,8 @@ import System.FilePath ( (<.>) ) import System.Directory ( doesFileExist ) +import System.IO.Error + ( isDoesNotExistError ) data DownloadResult = FileAlreadyInCache | FileDownloaded FilePath deriving (Eq) @@ -88,13 +92,16 @@ cabalBrowse :: Verbosity -> IO a cabalBrowse verbosity auth act = do p <- proxy verbosity - browse $ do - setProxy p - setErrHandler (warn verbosity . ("http error: "++)) - setOutHandler (debug verbosity) - auth - setAuthorityGen (\_ _ -> return Nothing) - act + handleJust + (guard . isDoesNotExistError) + (const $ die "Cannot connect to uri. Is http_proxy set?") $ + browse $ do + setProxy p + setErrHandler (warn verbosity . ("http error: "++)) + setOutHandler (debug verbosity) + auth + setAuthorityGen (\_ _ -> return Nothing) + act downloadURI :: Verbosity -> URI -- ^ What to download -- 1.7.9.5
pgp1Ni1VsYn4z.pgp
Description: PGP signature
_______________________________________________ cabal-devel mailing list cabal-devel@haskell.org http://www.haskell.org/mailman/listinfo/cabal-devel