Skip to content

Commit

Permalink
Bring back cross-platform compat for rootCause
Browse files Browse the repository at this point in the history
Revert "Make rootCause cross-platform without shims"
This reverts commit 106fe8b.
And commit 038e96b.
  • Loading branch information
valencik committed Jun 28, 2022
1 parent ddf1120 commit de2997f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package munit.internal

class InvocationTargetException extends java.lang.RuntimeException
4 changes: 4 additions & 0 deletions munit/js/src/main/scala/munit/internal/PlatformCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ object PlatformCompat {
private var myClassLoader: ClassLoader = _
def setThisClassLoader(loader: ClassLoader): Unit = myClassLoader = loader
def getThisClassLoader: ClassLoader = myClassLoader

type InvocationTargetException = munit.internal.InvocationTargetException
type UndeclaredThrowableException =
munit.internal.UndeclaredThrowableException
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package munit.internal

class UndeclaredThrowableException extends java.lang.RuntimeException
4 changes: 4 additions & 0 deletions munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ object PlatformCompat {
def isJS: Boolean = false
def isNative: Boolean = false
def getThisClassLoader: ClassLoader = this.getClass().getClassLoader()

type InvocationTargetException = java.lang.reflect.InvocationTargetException
type UndeclaredThrowableException =
java.lang.reflect.UndeclaredThrowableException
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ object PlatformCompat {
private var myClassLoader: ClassLoader = _
def setThisClassLoader(loader: ClassLoader): Unit = myClassLoader = loader
def getThisClassLoader: ClassLoader = myClassLoader

type InvocationTargetException = java.lang.reflect.InvocationTargetException
type UndeclaredThrowableException =
java.lang.reflect.UndeclaredThrowableException
}
6 changes: 5 additions & 1 deletion munit/shared/src/main/scala/munit/Exceptions.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package munit

import munit.internal.PlatformCompat.InvocationTargetException
import munit.internal.PlatformCompat.UndeclaredThrowableException

import java.util.concurrent.ExecutionException
import scala.annotation.tailrec

Expand All @@ -9,7 +12,8 @@ object Exceptions {
// these exception in order to provide more helpful error messages.
@tailrec
def rootCause(x: Throwable): Throwable = x match {
case _: ExceptionInInitializerError | _: ExecutionException
case _: InvocationTargetException | _: ExceptionInInitializerError |
_: UndeclaredThrowableException | _: ExecutionException
if x.getCause != null =>
rootCause(x.getCause)
case _ => x
Expand Down

0 comments on commit de2997f

Please sign in to comment.