question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception thrown when using attempt

See original GitHub issue

I am on version 2.2.0 I’ve been playing around with essential effects repo running the code titled ParMapNErrors


object ParMapNErrors extends IOApp {
  def run(args: List[String]): IO[ExitCode] =
    e1.attempt.debug *>
      IO("---").debug *>
      e2.attempt.debug *>
      IO("---").debug *>
      e3.attempt.debug *>
      IO.pure(ExitCode.Success)

  val ok = IO("hi").debug
  // how will debug ever evaluate
  val ko1 = IO.raiseError[String](new RuntimeException("oh!")).debug
  val ko2 = IO.raiseError[String](new RuntimeException("noes!")).debug

  val e1 = (ok, ko1).parTupled.void
  val e2 = (ko1, ok).parMapN((_, _) => ())
  val e3 = (ko1, ko2).parMapN((_, _) => ())

}

running this code both from Intellij and Sbt with (ThisBuild / fork := true) multiple times resulted in some occurrences generating the following stack trace

[info] running (fork) com.innerproduct.ee.parallel.ParMapNErrors 
[info] in debug mode: [ioapp-compute-1] hi
[info] in debug mode: [ioapp-compute-2] Left(java.lang.RuntimeException: oh!)
[info] in debug mode: [ioapp-compute-2] ---
[info] in debug mode: [ioapp-compute-2] hi
[info] in debug mode: [ioapp-compute-3] Left(java.lang.RuntimeException: oh!)
[info] in debug mode: [ioapp-compute-3] ---
[info] in debug mode: [ioapp-compute-1] Left(java.lang.RuntimeException: oh!)
[error] java.lang.RuntimeException: noes!
[error]         at com.innerproduct.ee.parallel.ParMapNErrors$.<clinit>(ParMapNErrors.scala:19)
[error]         at com.innerproduct.ee.parallel.ParMapNErrors.main(ParMapNErrors.scala)
[error]         at map @ com.innerproduct.ee.debug$DebugHelper.debug(debug.scala:15)
[error]         at map @ com.innerproduct.ee.debug$DebugHelper.debug(debug.scala:15)
[error]         at main$ @ com.innerproduct.ee.parallel.ParMapNErrors$.main(ParMapNErrors.scala:7)

For reference the “in debug mode…” is from a helper class

object debug {
  /** Extension methods for an effect of type `F[A]`. */
  implicit class DebugHelper[A](ioa: IO[A]) {

    /** Print to the console the value of the effect
     * along with the thread it was computed on. */
    def debug: IO[A] =
      for {
        a <- ioa
        tn = Thread.currentThread.getName
        _ = println(s"in debug mode: [${Colorize.reversed(tn)}] $a") // <1>
      } yield a
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
arosiencommented, Aug 4, 2021

I think runtime is printing the stacktrace of the loser of the race between ko1 and ko2, and this has nothing to do with the use of attempt.

1reaction
yisraelUcommented, Aug 4, 2021

@vasilmkd I received the same results

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Throw Exceptions (The Java™ Tutorials > Essential ...
All methods use the throw statement to throw an exception. The throw statement requires a single argument: a throwable object. Throwable objects are...
Read more >
Reading from a Database throws exception on second attempt?
My bet is that something is not getting disposed of properly. Try modifying your code to use using statements: using(var northwindConnection ...
Read more >
Attempt take snapshot on application thread in state ...
How to troubleshoot the exception thrown when executing a IronPython script with the error: Attempt take snapshot on application thread in ...
Read more >
How to Fix the Empty Stack Exception in Java - Rollbar
The EmptyStackException is a runtime exception in Java that is thrown by methods in the Stack class to indicate that the stack is...
Read more >
C++ Exception Handling - Tutorialspoint
Exceptions can be thrown anywhere within a code block using throw statement. The operand of the throw statement determines a type for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found