Exception thrown when using attempt
See original GitHub issueI 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:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think runtime is printing the stacktrace of the loser of the race between
ko1
andko2
, and this has nothing to do with the use ofattempt
.@vasilmkd I received the same results