cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Wrong async stacktrace

Open kpodsiad opened this issue 3 years ago • 1 comments

Discussed in https://github.com/typelevel/cats-effect/discussions/2981

Originally posted by kpodsiad May 7, 2022 The following snippet

//> using scala "2.13.8"
//> using lib "org.typelevel::cats-effect:3.3.11"

package a

import cats.effect.IOApp
import cats.effect.IO

object Main extends IOApp.Simple {
  val io = IO(5)
  val x = List()
  override def run: IO[Unit] = io
    .flatMap(_ => IO(x(5)))
    .void
}

produces following stacktrace

java.lang.IndexOutOfBoundsException: 5
        at scala.collection.LinearSeqOps.apply(LinearSeq.scala:117)
        at scala.collection.LinearSeqOps.apply$(LinearSeq.scala:114)
        at scala.collection.immutable.List.apply(List.scala:79)
        at a.Main$.$anonfun$run$2(Stacktraces.scala:13)
        at apply @ a.Main$.$anonfun$run$1(Stacktraces.scala:13)
        at apply @ a.Main$.<clinit>(Stacktraces.scala:10)
        at flatMap @ a.Main$.run(Stacktraces.scala:13)
        at void @ a.Main$.run(Stacktraces.scala:13)
        at run$ @ a.Main$.run(Stacktraces.scala:9)

at void @ a.Main$.run(Stacktraces.scala:13) looks wrong to me, shouldn't it be line 14 instead?

kpodsiad avatar May 07 '22 15:05 kpodsiad

If anyone wants to fiddle with this, it would probably be in this file: https://github.com/typelevel/cats-effect/blob/76d2602ea651a6f0035bef4f9aa506773a335c95/core/shared/src/main/scala/cats/effect/tracing/Tracing.scala

armanbilge avatar May 07 '22 16:05 armanbilge

Strangely, the original stacktrace already seems to be incorrect:

package com.example

object Bar {

  def self(x: Any): Bar.type =
    this

  def void(): Unit =
    throw new Exception

  def main(args: Array[String]): Unit = {
    this
      .self((x: Int) => x)
      .void() // this is line 14
  }
}
java.lang.Exception
        at com.example.Bar$.void(Foo.scala:9)
        at com.example.Bar$.main(Foo.scala:13)
        at com.example.Bar.main(Foo.scala)
        ...

Note 13 instead of 14.

durban avatar Apr 24 '23 15:04 durban

Nice find! It also affects Scala 3. I think we can say this is not our bug, and possibly not a bug at all? Let's see what the dotty team says.

  • https://github.com/lampepfl/dotty/issues/17425

armanbilge avatar May 06 '23 03:05 armanbilge