<commit_before>package org.broadinstitute.hail

import java.lang.reflect.Method
import java.net.URI

import org.apache.hadoop.fs.PathIOException
import org.apache.hadoop.mapred.FileSplit
import org.apache.hadoop.mapreduce.lib.input.{FileSplit => NewFileSplit}
import org.apache.spark.{AccumulableParam, Partition}
import org.broadinstitute.hail.check.Gen
import org.json4s.{Formats, JValue, NoTypeHints}
import org.json4s.Extraction.decompose
import org.json4s.jackson.Serialization

import scala.collection.generic.CanBuildFrom
import scala.collection.{GenTraversableOnce, TraversableOnce, mutable}
import scala.language.{higherKinds, implicitConversions}
import scala.reflect.ClassTag

package object utils extends Logging
  with richUtils.Implicits
  with utils.NumericImplicits {

  class FatalException(val msg: String, val logMsg: Option[String] = None) extends RuntimeException(msg)

  def digForFatal(e: Throwable): Option[String] = {
    val r = e match {
      case f: FatalException =>
        println(s"found fatal $f")
        Some(s"${ e.getMessage }")
      case _ =>
        Option(e.getCause).flatMap(c => digForFatal(c))
    }
    r
  }

  def deepestMessage(e: Throwable): String = {
    var iterE = e
    while (iterE.getCause != null)
      iterE = iterE.getCause

    s"${ e.getClass.getSimpleName }: ${ e.getLocalizedMessage }"
  }

  def expandException(e: Throwable): String = {
    val msg = e match {
      case f: FatalException => f.logMsg.getOrElse(f.msg)
      case _ => e.getLocalizedMessage
    }
    s"${ e.getClass.getName }: $msg\n\tat ${ e.getStackTrace.mkString("\n\tat ") }${
      Option(e.getCause).map(exception => expandException(exception)).getOrElse("")
    }"
  }

  def getMinimalMessage(e: Exception): String = {
    val fatalOption = digForFatal(e)
    val prefix = if (fatalOption.isDefined) "fatal" else "caught exception"
    val msg = fatalOption.getOrElse(deepestMessage(e))<commit_msg>Fix python error messages (#1206)<commit_after>package org.broadinstitute.hail

import java.lang.reflect.Method
import java.net.URI

import org.apache.hadoop.fs.PathIOException
import org.apache.hadoop.mapred.FileSplit
import org.apache.hadoop.mapreduce.lib.input.{FileSplit => NewFileSplit}
import org.apache.spark.{AccumulableParam, Partition}
import org.broadinstitute.hail.check.Gen
import org.json4s.{Formats, JValue, NoTypeHints}
import org.json4s.Extraction.decompose
import org.json4s.jackson.Serialization

import scala.collection.generic.CanBuildFrom
import scala.collection.{GenTraversableOnce, TraversableOnce, mutable}
import scala.language.{higherKinds, implicitConversions}
import scala.reflect.ClassTag

package object utils extends Logging
  with richUtils.Implicits
  with utils.NumericImplicits {

  class FatalException(val msg: String, val logMsg: Option[String] = None) extends RuntimeException(msg)

  def digForFatal(e: Throwable): Option[String] = {
    val r = e match {
      case f: FatalException =>
        println(s"found fatal $f")
        Some(s"${ e.getMessage }")
      case _ =>
        Option(e.getCause).flatMap(c => digForFatal(c))
    }
    r
  }

  def deepestMessage(e: Throwable): String = {
    var iterE = e
    while (iterE.getCause != null)
      iterE = iterE.getCause

    s"${ iterE.getClass.getSimpleName }: ${ iterE.getLocalizedMessage }"
  }

  def expandException(e: Throwable): String = {
    val msg = e match {
      case f: FatalException => f.logMsg.getOrElse(f.msg)
      case _ => e.getLocalizedMessage
    }
    s"${ e.getClass.getName }: $msg\n\tat ${ e.getStackTrace.mkString("\n\tat ") }${
      Option(e.getCause).map(exception => expandException(exception)).getOrElse("")
    }"
  }

  def getMinimalMessage(e: Exception): String = {
    val fatalOption = digForFatal(e)
    val prefix = if (fatalOption.isDefined) "fatal" else "caught exception"
    val msg = fatalOption.getOrElse(deepestMessage(e))
{'fraction_non_alphanumeric': 0.11847492323439099, 'fraction_numerical': 0.00255885363357216, 'mean_word_length': 4.0438709677419356, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '934601', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1272, 'n_words': 261}