Skip to content

Commit

Permalink
ReflectionException: add flatten() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Nov 26, 2021
1 parent 7b38b55 commit e43801c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,8 @@ final case class ScalafmtDynamic(
val configWithDialect: ScalafmtReflectConfig =
if (needSbt) config.withSbtDialect else config
configWithDialect.format(code, Some(file))
}.toEither.left.map {
case ReflectionException(e) => UnknownError(e)
case e => UnknownError(e)
}.toEither.left.map { x =>
UnknownError(ReflectionException.flatten(x))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package org.scalafmt.dynamic.exceptions
import java.lang.reflect.InvocationTargetException

object ReflectionException {
def unapply(e: Throwable): Option[Throwable] =
e match {
case e: InvocationTargetException => Some(e.getCause)
case _ => Some(e)
}
def unapply(e: Throwable): Option[Throwable] = Some(flatten(e))

def flatten(e: Throwable): Throwable = e match {
case e: InvocationTargetException => e.getCause
case _ => e
}
}

0 comments on commit e43801c

Please sign in to comment.