-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from scalameta/rootcause
Expose rootCause util
- Loading branch information
Showing
2 changed files
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package munit | ||
|
||
import munit.internal.PlatformCompat.InvocationTargetException | ||
import munit.internal.PlatformCompat.UndeclaredThrowableException | ||
|
||
import java.util.concurrent.ExecutionException | ||
import scala.annotation.tailrec | ||
|
||
object Exceptions { | ||
|
||
// NOTE(olafur): these exceptions appear when we await on futures. We unwrap | ||
// these exception in order to provide more helpful error messages. | ||
@tailrec | ||
def rootCause(x: Throwable): Throwable = x match { | ||
case _: InvocationTargetException | _: ExceptionInInitializerError | | ||
_: UndeclaredThrowableException | _: ExecutionException | ||
if x.getCause != null => | ||
rootCause(x.getCause) | ||
case _ => x | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters