title: FS2 Stream exception handling not working
body: <p>I am having a problem with FS2 and exception handling. What I want is that, given a <code>Stream[IO,A]</code>, when I map on it using an <code>f: A =&gt; B</code> that can throw exception,  I obtain a <code>Stream[IO,Either[Throwable,B]]</code>. </p>
  
  <p>I tried the following, and it works as expected:</p>
  
  <pre><code>import cats.effect.IO
  val x1 = fs2.Stream.emits(Vector(1,2,3,4)).covary[IO]
    .map(x =&gt; x * x)
    .map{ i =&gt; if(i == 9) throw new RuntimeException("I don't like 9s") else i}
    .attempt
  x1.compile.toVector.unsafeRunSync().foreach(println)
  </code></pre>
  
  <p>It prints: </p>
  
  <pre><code>Right(1)
  Right(4)
  Left(java.lang.RuntimeException: I don't like 9s)
  </code></pre>
  
  <p>However, my problems start when I try to do anything with that <code>Stream</code>. </p>
  
  <pre><code>val x1 = fs2.Stream.emits(Vector(1,2,3,4)).covary[IO]
    .map(x =&gt; x * x)
    .map{ i =&gt; if(i == 9) throw new RuntimeException("I don't like 9s") else i}
    .attempt.map(identity)
  
  x1.compile.toVector.unsafeRunSync().foreach(println)
  </code></pre>
  
  <p>Blows up with the exception and kills the application: </p>
  
  <pre><code>java.lang.RuntimeException: I don't like 9s
      at swaps.fm.A$A32$A$A32.$anonfun$x1$2(tmp2.sc:7)
      at scala.runtime.java8.JFunction1$mcII$sp.apply(tmp2.sc:8)
      ...
  </code></pre>
  
  <p>Even weirder, using <code>take</code> to have the <code>Stream</code> return only the elements that I know to be OK, still blows up in the same way: </p>
  
  <pre><code>val x1 = fs2.Stream.emits(Vector(1,2,3,4)).covary[IO]
    .map(x =&gt; x * x)
    .map{ i =&gt; if(i == 9) throw new RuntimeException("I don't like 9s") else i}
    .attempt.take(2)
  
  x1.compile.toVector.unsafeRunSync().foreach(println)
  </code></pre>
  
  <p>Can anybody clarify why this is happening? Is this a bug or (un)expected behaviour?</p>
  
  <p><strong>N.B.</strong> This behaviour is present in FS2 <strong>0.10.0-M7</strong> and <strong>0.10.0</strong></p>