Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing information about failing background fibers #2842

Closed
ghostbuster91 opened this issue Feb 24, 2022 · 4 comments
Closed

Missing information about failing background fibers #2842

ghostbuster91 opened this issue Feb 24, 2022 · 4 comments

Comments

@ghostbuster91
Copy link

ghostbuster91 commented Feb 24, 2022

Tested against 3.3.0 and 3.3.5

Following code doesn't print any information about the fact that an exception was thrown in one of the fibers.

object Main extends IOApp {
  override def run(args: List[String]): IO[ExitCode] = {
    Thread.setDefaultUncaughtExceptionHandler((t, e) => println("Uncaught exception in thread: " + t, e))
    for {
      _ <- IO
        .sleep(5.seconds)
        .flatMap(_ => IO.delay(println("after sleep")))
        .flatMap(_ => IO.raiseError(new RuntimeException("something went wrong")))
        .start
      _ <- IO.delay(println("started"))
      _ <- IO.never[Unit]
    } yield ExitCode.Success
  }
}

I would expect it to print some information to stdout/stderr. It would be even better if there was a way to customize that information.

For example in zio there is a Plaform object that contains an error reporter which can be customized by the user.

In the Platform that is a part of every runtime, there is an error reporter that will be called by ZIO to report every unhandled error

Link to the original discussion on discord: https://discord.com/channels/632277896739946517/632278585700384799/946443755286855702

@armanbilge
Copy link
Member

armanbilge commented Feb 24, 2022

Btw, I wondered if there's some way to make a Supervisor-like thing to help with this situation as well (possibly in addition to dealing with it at the runtime-level). It seems like this is exactly the kind of thing to supervise 😉

trait ErrorSupervisor[F[_]] {
  def supervise[A](fa: F[A]): F[Fiber[F, Throwable, A]]
  def error: F[Throwable] // semantically blocks until the first error
}

@ghostbuster91
Copy link
Author

I must admit that it crossed my mind to check whether the Supervisor doesn't have any kind of option for that. I like that direction :)

@djspiewak
Copy link
Member

Btw I realized that we do have an obvious place to put this: the compute ExecutionContext. In fact, it's already there. We don't have a good way of modifying it, but it does exist and we simply don't use it on fiber termination. This should be fixed, and we should add a better way of adjusting the handler.

@ghostbuster91
Copy link
Author

Somehow it didn't get closed automatically 🤔 Closing as it was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants