Created
September 19, 2013 22:42
-
-
Save przemek-pokrywka/6630871 to your computer and use it in GitHub Desktop.
Small utility to clean up longish stacktraces. All comments how to make it more generic warmly welcome.
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
object StackTraceHelper | |
{ | |
def retainWithBorder [T] (items: Seq[T], | |
valuable: (T => Boolean)): Seq[T] = | |
{ | |
if (items.size < 3) return items | |
val retained = for | |
{ | |
slice <- items.sliding (3) | |
if slice.exists (valuable) | |
} yield slice (1) | |
Seq(items.head) ++ retained ++ Seq(items.last) | |
} | |
def clean (exception: Throwable, valuable: StackTraceElement => Boolean) = | |
{ | |
val originalTrace = exception.getStackTrace | |
val filteredStack = retainWithBorder (originalTrace, valuable).toArray | |
exception.setStackTrace (filteredStack) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment