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

Simplify and expose munit's rootCause util #541

Closed
valencik opened this issue Jun 25, 2022 · 0 comments · Fixed by #542
Closed

Simplify and expose munit's rootCause util #541

valencik opened this issue Jun 25, 2022 · 0 comments · Fixed by #542

Comments

@valencik
Copy link
Collaborator

Munit has a handy utility for unwrapping exceptions to provide better error messages.

rootCause:

  private def rootCause(x: Throwable): Throwable = x match {
    case _: InvocationTargetException | _: ExceptionInInitializerError |
        _: UndeclaredThrowableException | _: ExecutionException
        if x.getCause != null =>
      rootCause(x.getCause)
    case _ => x
  }

This was introduce in #277 where it was ultimately copied from a Scala compiler util.

  1. I think we should expose rootCause under private[munit] so that third-party integrations like scalacheck-effect can use it without copying.

  2. We should remove the handling of InvocationTargetException and UndeclaredThrowableException, which are not available on ScalaJS.

I think the Scala compiler util included InvocationTargetException and UndeclaredThrowableException because it was used in signal handling code that dealt with more than just Futures. I think you can see this in the PR that introduced UndeclaredThrowableException to this code: scala/scala@1fcb865#diff-6624212dec6b02c76a7ef6d0a388f0d0f6b9ad71b520020d493d5c4880d9db3fR120

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

Successfully merging a pull request may close this issue.

1 participant