typelevel / typelevel/cats-effect

Failed fibers does not log when run with `scala-cli`

Open
#3,640 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
576
Avg merge
2d 11h
Merged PRs (30d)
18

Description

This script wont log error when run with scala-cli:

//> using scala "3.2.1"
//> using option "-new-syntax"

//> using dep "org.typelevel::cats-effect:3.5.0"

import cats.effect.*

object Main extends IOApp.Simple:
  val run: IO[Unit] = IO
    .raiseError(new Exception("Boom!"))
    .background
    .use { out =>
      out.flatMap(IO.println(_))
    }
$> scala-cli test.scala
Errored(java.lang.Exception: Boom!)

(Almost) the same code prints error when run from sbt console:

Attached file wont print stack trace in when run with scala-cli in terminal.

At the same time, `sbt console` prints it:

```console
scala> import cats.effect.*
scala> import cats.effect.unsafe.implicits.*
scala> IO.raiseError(new Exception("Boom!")).background.use(out => out.flatMap(IO.println(_)))
val res0: cats.effect.IO[Unit] = IO(...)

scala> res0.unsafeRunSync()
java.lang.Exception: Boom!
    at rs$line$3$.<clinit>(rs$line$3:1)
    at rs$line$3.res0(rs$line$3)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at dotty.tools.repl.Rendering.$anonfun$4(Rendering.scala:106)
    at scala.Option.flatMap(Option.scala:283)
    at dotty.tools.repl.Rendering.valueOf(Rendering.scala:106)
    at dotty.tools.repl.Rendering.renderVal(Rendering.scala:149)
    at dotty.tools.repl.ReplDriver.$anonfun$7(ReplDriver.scala:365)
Errored(java.lang.Exception: Boom!)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the script shown in the issue with scala-cli and compare its output with the equivalent expression run through sbt console. Read the cats-effect background usage and the reported console output to identify where the exception is handled differently; done means the scala-cli run logs the exception with a stack trace like sbt console.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.