This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap-core".

The branch, master has been updated
       via  3e36f67dc8f544cddc6aa75c21a8baa12f2ec0c2 (commit)
       via  5468e6ee36bf0a9071dceb7a5f484164caae252e (commit)
      from  70121ac0e6c9665d2069523e067b28b03aa11784 (commit)


Summary of changes:
 src/Snap/Iteratee.hs              |   17 ++++++++++++++---
 test/suite/Snap/Iteratee/Tests.hs |   24 ++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 5 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3e36f67dc8f544cddc6aa75c21a8baa12f2ec0c2
Author: Gregory Collins <[email protected]>
Date:   Fri Feb 11 15:40:37 2011 -0800

    Fix the MonadCatchIO instance for iteratee (closes #48)

diff --git a/src/Snap/Iteratee.hs b/src/Snap/Iteratee.hs
index 9660897..7891004 100644
--- a/src/Snap/Iteratee.hs
+++ b/src/Snap/Iteratee.hs
@@ -138,17 +138,28 @@ instance (Functor m, MonadCatchIO m) =>
         ee <- try $ runIteratee (m `catchError` h)
         case ee of
           (Left e)  -> runIteratee (handler e)
-          (Right v) -> return v
+          (Right v) -> step v
       where
+        step (Continue k)  = return $ Continue (\s -> k s `catch` handler)
+        -- don't worry about Error here because the error had to come from the
+        -- handler (because of 'catchError' above)
+        step y             = return y
+
         -- we can only catch iteratee errors if "e" matches "SomeException"
         h e = maybe (throwError e)
                     (handler)
                     (fromException e)
 
     --block :: m a -> m a
-    block m = Iteratee $ block $ runIteratee m
-    unblock m = Iteratee $ unblock $ runIteratee m
+    block m = Iteratee $ block $ (runIteratee m >>= step)
+      where
+        step (Continue k) = return $ Continue (\s -> block (k s))
+        step y            = return y
 
+    unblock m = Iteratee $ unblock $ (runIteratee m >>= step)
+      where
+        step (Continue k) = return $ Continue (\s -> unblock (k s))
+        step y            = return y
 
 
 ------------------------------------------------------------------------------
commit 5468e6ee36bf0a9071dceb7a5f484164caae252e
Author: Gregory Collins <[email protected]>
Date:   Fri Feb 11 15:08:56 2011 -0800

    Add (incorrectly) failing test for MonadCatchIO iteratee instance

diff --git a/test/suite/Snap/Iteratee/Tests.hs 
b/test/suite/Snap/Iteratee/Tests.hs
index d693bb1..537a65b 100644
--- a/test/suite/Snap/Iteratee/Tests.hs
+++ b/test/suite/Snap/Iteratee/Tests.hs
@@ -8,8 +8,9 @@ module Snap.Iteratee.Tests
 
 import           Control.Concurrent (threadDelay)
 import qualified Control.Exception as E
-import           Control.Exception hiding (try, assert)
+import           Control.Exception hiding (try, assert, throw, catch)
 import           Control.Monad
+import           Control.Monad.CatchIO
 import           Control.Monad.Identity
 import           Control.Monad.Trans
 import qualified Data.ByteString.Base16 as B16
@@ -18,7 +19,7 @@ import qualified Data.ByteString.Char8 as S
 import qualified Data.ByteString.Lazy.Char8 as L
 import           Data.Int
 import           Data.Maybe
-import           Prelude hiding (head, drop, take)
+import           Prelude hiding (catch, head, drop, take)
 import           System.Timeout
 import           Test.Framework
 import           Test.Framework.Providers.QuickCheck2
@@ -78,6 +79,7 @@ tests = [ testEnumBS
         , testKillIfTooSlow1
         , testKillIfTooSlow2
         , testKMP
+        , testCatchIO
         ]
 
 testEnumBS :: Test
@@ -505,6 +507,24 @@ testKillIfTooSlow2 = testCase "iteratee/killIfTooSlow2" $ 
do
     H.assertEqual "testKillIfTooSlow2" (S.replicate 300 'f') m
 
 
+
+------------------------------------------------------------------------------
+testCatchIO :: Test
+testCatchIO = testCase "iteratee/monadCatchIO" $ do
+    e <- run_ $ enumList 1 ["1", "2", "3", "4", "5"] $$ iter 0
+    H.assertBool "handled exception" $ isJust e
+
+  where
+    iter !i = (continue $ k (i::Int)) `catch` h
+
+    k _ EOF = return Nothing
+    k i _   = if i >= 2
+                then throw $ ErrorCall "should not escape!"
+                else iter (i+1)
+
+    h :: SomeException -> Iteratee ByteString IO (Maybe String)
+    h e = return $ Just $ show e
+
 ------------------------------------------------------------------------------
 tooSlowEnum :: Int -> Enumerator ByteString IO a
 tooSlowEnum ntimes (Continue k) = do
-----------------------------------------------------------------------


hooks/post-receive
-- 
snap-core
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to