From de2997f21d39ded60c0006e9365188fd6a6616d5 Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Tue, 28 Jun 2022 08:54:30 -0400 Subject: [PATCH] Bring back cross-platform compat for rootCause Revert "Make rootCause cross-platform without shims" This reverts commit 106fe8b5bd1ff1e548f43fd1764f2281865505f7. And commit 038e96b719f20410210821b7302a2eb017c77e9b. --- .../scala/munit/internal/InvocationTargetException.scala | 3 +++ munit/js/src/main/scala/munit/internal/PlatformCompat.scala | 4 ++++ .../scala/munit/internal/UndeclaredThrowableException.scala | 3 +++ .../jvm/src/main/scala/munit/internal/PlatformCompat.scala | 4 ++++ .../src/main/scala/munit/internal/PlatformCompat.scala | 4 ++++ munit/shared/src/main/scala/munit/Exceptions.scala | 6 +++++- 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 munit/js/src/main/scala/munit/internal/InvocationTargetException.scala create mode 100644 munit/js/src/main/scala/munit/internal/UndeclaredThrowableException.scala diff --git a/munit/js/src/main/scala/munit/internal/InvocationTargetException.scala b/munit/js/src/main/scala/munit/internal/InvocationTargetException.scala new file mode 100644 index 00000000..d83734e3 --- /dev/null +++ b/munit/js/src/main/scala/munit/internal/InvocationTargetException.scala @@ -0,0 +1,3 @@ +package munit.internal + +class InvocationTargetException extends java.lang.RuntimeException diff --git a/munit/js/src/main/scala/munit/internal/PlatformCompat.scala b/munit/js/src/main/scala/munit/internal/PlatformCompat.scala index 3c238de7..f5fb39dd 100644 --- a/munit/js/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/js/src/main/scala/munit/internal/PlatformCompat.scala @@ -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 } diff --git a/munit/js/src/main/scala/munit/internal/UndeclaredThrowableException.scala b/munit/js/src/main/scala/munit/internal/UndeclaredThrowableException.scala new file mode 100644 index 00000000..86497cb6 --- /dev/null +++ b/munit/js/src/main/scala/munit/internal/UndeclaredThrowableException.scala @@ -0,0 +1,3 @@ +package munit.internal + +class UndeclaredThrowableException extends java.lang.RuntimeException diff --git a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala index d8b85a31..276307a0 100644 --- a/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/jvm/src/main/scala/munit/internal/PlatformCompat.scala @@ -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 } diff --git a/munit/native/src/main/scala/munit/internal/PlatformCompat.scala b/munit/native/src/main/scala/munit/internal/PlatformCompat.scala index c08636e4..a4ab1294 100644 --- a/munit/native/src/main/scala/munit/internal/PlatformCompat.scala +++ b/munit/native/src/main/scala/munit/internal/PlatformCompat.scala @@ -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 } diff --git a/munit/shared/src/main/scala/munit/Exceptions.scala b/munit/shared/src/main/scala/munit/Exceptions.scala index 550a436c..11709a5d 100644 --- a/munit/shared/src/main/scala/munit/Exceptions.scala +++ b/munit/shared/src/main/scala/munit/Exceptions.scala @@ -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 @@ -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