Yes, this is expected.  &#39;throwErr&#39; is only meant to be used when the error should be non-recoverable, and the stream would often be invalid then, so throwErr doesn&#39;t take any steps to preserve it.  You could retain the rest of the stream with getChunk and use throwRecoverableErr though.<br>
<br>Wrapping an iteratee with ErrorT is fine, and I use this approach often.  I typically would use an explicit Either rather than ErrorT, but the two approaches are exactly the same.<br><br>Note that wrapping the other way, Iteratee s (ErrorT e m), can sometimes cause problems, and is best avoided unless you really know what you&#39;re doing.  This may change in a future release.<br>
<br>John<br><br>On Thu, Jun 2, 2011 at 4:27 PM, Sergey Mironov <span dir="ltr">&lt;<a href="mailto:ierton@gmail.com" target="_blank">ierton@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I am glad to help! Looks like upgrading to 0.8.5.0 also fixes initial<br>
problem that involved me into testing!<br>
<br>
I&#39;ll take the opportunity and ask another thing about iteratee: Is it<br>
expected behavior that throwErr consumes all data in current chunk? I<br>
wish it to stop in place and let after-checkErr code to continue the<br>
parsing. Well, I already found solution (or workaround?) - I wrap<br>
Iteratee with ErrorT monad and use ErrorT&#39;s raiseError instead of<br>
throwErr. Is it correct?<br>
<br>
Here is example code<br>
<br>
instance Exception Int<br>
<br>
iter4 = do<br>
    I.dropWhile (/= 3)<br>
    h&lt;-I.head<br>
    throwErr $ toException $ (-4::Int)  -- doesn&#39;t meter what exactly to throw<br>
    return h<br>
<br>
-- catch the error with checkErr<br>
iter5 = do<br>
    (_,b)&lt;-countBytes $ I.checkErr $ iter4<br>
    s &lt;- I.stream2list<br>
    return (b,s)<br>
<br>
print5 = enumPure1Chunk [1..10] (iter5) &gt;&gt;= run &gt;&gt;= print<br>
<br>
<br>
Thanks a lot!<br>
<div><div></div><div>Sergey<br>
<br>
2011/6/2 John Lato &lt;<a href="mailto:jwlato@gmail.com" target="_blank">jwlato@gmail.com</a>&gt;:<br>
&gt; Hi Sergey,<br>
&gt;<br>
&gt; I&#39;ve got an explanation; quite surprisingly it&#39;s a bug in enumPure1Chunk.<br>
&gt; Even though it is an odd case, I&#39;m surprised that it hasn&#39;t come up before<br>
&gt; now since enumPure1Chunk appears frequently.<br>
&gt;<br>
&gt; I&#39;ve just uploaded 0.8.5.0 which has the fix.  There&#39;s now an additional<br>
&gt; Monoid constraint on enumPure1Chunk, unfortunately.<br>
&gt;<br>
&gt; Thanks very much for reporting this.<br>
&gt;<br>
&gt; John L<br>
&gt;<br>
&gt; On Thu, Jun 2, 2011 at 10:02 AM, Sergey Mironov &lt;<a href="mailto:ierton@gmail.com" target="_blank">ierton@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Ok. I&#39;ve checked iteratee-0.8.3.0 and 0.8.4.0. Results are same.<br>
&gt;&gt;<br>
&gt;&gt; Sergey<br>
&gt;&gt;<br>
&gt;&gt; 2011/6/2 John Lato &lt;<a href="mailto:jwlato@gmail.com" target="_blank">jwlato@gmail.com</a>&gt;:<br>
&gt;&gt; &gt; Hi Sergey,<br>
&gt;&gt; &gt; I can&#39;t explain this; maybe it&#39;s a bug in enumWith?  I&#39;ll look into it.<br>
&gt;&gt; &gt; Thanks,<br>
&gt;&gt; &gt; John<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Message: 20<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Date: Thu, 2 Jun 2011 02:46:32 +0400<br>
&gt;&gt; &gt;&gt; From: Sergey Mironov &lt;<a href="mailto:ierton@gmail.com" target="_blank">ierton@gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt; Subject: [Haskell-cafe] [iteratee] how to do nothing .. properly<br>
&gt;&gt; &gt;&gt; To: <a href="mailto:haskell-cafe@haskell.org" target="_blank">haskell-cafe@haskell.org</a><br>
&gt;&gt; &gt;&gt; Message-ID: &lt;BANLkTimMFRWgH9Nopt-eua+L7jQcGq+u=<a href="mailto:g@mail.gmail.com" target="_blank">g@mail.gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt; Content-Type: text/plain; charset=ISO-8859-1<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hi. Would anybody explain a situation with iter6 and iter7 below?<br>
&gt;&gt; &gt;&gt; Strange thing - first one consumes no intput, while second consumes it<br>
&gt;&gt; &gt;&gt; all, while all the difference is peek  which should do no processing<br>
&gt;&gt; &gt;&gt; (just copy next item in stream and return to user).<br>
&gt;&gt; &gt;&gt; What I am trying to do - is to write an iteratee consuing no input,<br>
&gt;&gt; &gt;&gt; but returning a constant I give to it. I thought (return a) should do<br>
&gt;&gt; &gt;&gt; it, but it seems I was wrong as return actually consumes all unparsed<br>
&gt;&gt; &gt;&gt; stream. iter6 experience tells me that (peek&gt;&gt;return a) is what I<br>
&gt;&gt; &gt;&gt; need, but it&#39;s completely confusing and not what I expected.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Thanks,<br>
&gt;&gt; &gt;&gt; Sergey<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  import Data.Iteratee as I<br>
&gt;&gt; &gt;&gt;  import <a href="http://Data.Iteratee.IO" target="_blank">Data.Iteratee.IO</a><br>
&gt;&gt; &gt;&gt;  import Control.Monad<br>
&gt;&gt; &gt;&gt;  import Control.Exception<br>
&gt;&gt; &gt;&gt;  import Data.ByteString<br>
&gt;&gt; &gt;&gt;  import Data.Char<br>
&gt;&gt; &gt;&gt;  import Data.String<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  -- countBytes :: (..., Num b) =&gt; Iteratee s m a -&gt; Iteratee s m (a, b)<br>
&gt;&gt; &gt;&gt;  countBytes i = enumWith i I.length<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  iter6 = do<br>
&gt;&gt; &gt;&gt;     h &lt;- countBytes $ (peek &gt;&gt; return 0)<br>
&gt;&gt; &gt;&gt;     s &lt;- I.stream2list<br>
&gt;&gt; &gt;&gt;     return (h,s)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  iter7 = do<br>
&gt;&gt; &gt;&gt;     h &lt;- countBytes $ (return 0)<br>
&gt;&gt; &gt;&gt;     s &lt;- I.stream2list<br>
&gt;&gt; &gt;&gt;     return (h,s)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;  print6 = enumPure1Chunk [1..10] (iter6) &gt;&gt;= run &gt;&gt;= print<br>
&gt;&gt; &gt;&gt;  print7 = enumPure1Chunk [1..10] (iter7) &gt;&gt;= run &gt;&gt;= print<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Here is example ghci session<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; *Main&gt; print6<br>
&gt;&gt; &gt;&gt; ((0,0),[1,2,3,4,5,6,7,8,9,10])<br>
&gt;&gt; &gt;&gt; -- read 0 items, returns 0<br>
&gt;&gt; &gt;&gt; *Main&gt; print7<br>
&gt;&gt; &gt;&gt; ((0,10),[])<br>
&gt;&gt; &gt;&gt; -- read 10 items (???) returns 0<br>
&gt;&gt; &gt;&gt; *Main&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; ------------------------------<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; Haskell-Cafe mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
&gt;&gt; &gt;&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; End of Haskell-Cafe Digest, Vol 94, Issue 3<br>
&gt;&gt; &gt;&gt; *******************************************<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>