From 1aed59fcf3612061814858eb0bf8f42f8431ca72 Mon Sep 17 00:00:00 2001
From: Nikita Karetnikov <nikita@karetnikov.org>
Date: Mon, 12 Aug 2013 23:48:06 +0000
Subject: [PATCH 13/21] Replace 'TorDNSEL.Compat.Exception' with
 'Control.Exception'.

---
 src/TorDNSEL/ExitTest/Initiator/Internals.hs |   35 +++++++++++++++-----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/TorDNSEL/ExitTest/Initiator/Internals.hs b/src/TorDNSEL/ExitTest/Initiator/Internals.hs
index 4be908a..0e9ba73 100644
--- a/src/TorDNSEL/ExitTest/Initiator/Internals.hs
+++ b/src/TorDNSEL/ExitTest/Initiator/Internals.hs
@@ -62,10 +62,10 @@ import Prelude hiding (log)
 import Control.Arrow (first, second)
 import Control.Concurrent (threadDelay)
 import Control.Concurrent.Chan (Chan, newChan, writeChan, readChan)
-import qualified TorDNSEL.Compat.Exception as E
+import qualified Control.Exception as E
 import Control.Monad (replicateM_, guard, when)
 import qualified Data.ByteString.Char8 as B
-import Data.Dynamic (fromDynamic)
+import Data.Dynamic (fromDynamic, Dynamic)
 import qualified Data.Foldable as F
 import Data.List (foldl', unfoldr, mapAccumL)
 import qualified Data.Map as M
@@ -378,15 +378,19 @@ forkTestClient conf rid published port =
               B.hGet handle 1024 -- ignore response
               return ()
     case r of
-      Left e@(E.DynException d) | Just (e' :: SocksError) <- fromDynamic d -> do
-        log Info "Exit test for router " rid " port " port " failed: " e'
-        E.throwIO e
-      Left e -> do
-        log Warn "Exit test for router " rid " port " port " failed : " e
-                 ". This might indicate a problem with making application \
-                 \connections through Tor. Is Tor running? Is its SocksPort \
-                 \listening on " (eticfSocksServer conf) '?'
-        E.throwIO e
+      Left e
+        | Just (e' :: SocksError)
+          <- fromDynamic =<< (E.fromException e :: Maybe Dynamic)
+          -> do
+            log Info "Exit test for router " rid " port " port " failed: " e'
+            E.throwIO e
+        | otherwise
+          -> do
+            log Warn "Exit test for router " rid " port " port " failed : " e
+              ". This might indicate a problem with making application \
+              \connections through Tor. Is Tor running? Is its SocksPort \
+              \listening on " (eticfSocksServer conf) '?'
+            E.throwIO e
       Right Nothing ->
         log Info "Exit test for router " rid " port " port " timed out."
       _ ->
@@ -401,10 +405,11 @@ forkTestClient conf rid published port =
         connect sock (eticfSocksServer conf)
         socketToHandle sock ReadWriteMode
 
-    clientExceptions e@(E.DynException d)
-      | Just (_ :: SocksError) <- fromDynamic d = Just e
-    clientExceptions e@(E.IOException _)        = Just e
-    clientExceptions _                          = Nothing
+    clientExceptions e
+      | Just (_ :: SocksError)
+        <- fromDynamic =<< (E.fromException e :: Maybe Dynamic) = Just e
+      | Just _ <- E.fromException e :: Maybe E.IOException      = Just e
+      | otherwise                                               = Nothing
 
     connectionTimeout = 120 * 10^6
 
-- 
1.7.9.5

