<commit_before>package com.twitter.gizzard.proxy

import java.sql.SQLException
import shards.ShardId
import scala.reflect.Manifest
import com.twitter.querulous.database.SqlDatabaseTimeoutException
import com.twitter.querulous.query.SqlQueryTimeoutException
import com.twitter.querulous.evaluator.{QueryEvaluator, QueryEvaluatorProxy}


class SqlExceptionWrappingProxy(shardId: ShardId) extends ExceptionHandlingProxy({e =>
  e match {
    case e: SqlQueryTimeoutException =>
      throw new shards.ShardTimeoutException(e.timeout, shardId, e)
    case e: SqlDatabaseTimeoutException =>
      throw new shards.ShardDatabaseTimeoutException(e.timeout, shardId, e)
    case e: SQLException =>
      throw new shards.ShardException(e.toString, e)
    case e: shards.ShardException =>
      throw e
  }
})

class ShardExceptionWrappingQueryEvaluator(shardId: ShardId, evaluator: QueryEvaluator) extends QueryEvaluatorProxy(evaluator) {
  override protected def delegate[A](f: => A) = {
    try {
      f
    } catch {
      case e: SqlQueryTimeoutException =>
        throw new shards.ShardTimeoutException(e.timeout, shardId, e)
      case e: SqlDatabaseTimeoutException =>
        throw new shards.ShardDatabaseTimeoutException(e.timeout, shardId, e)
      case e: SQLException =>
        throw new shards.ShardException(e.toString, e)
      case e: shards.ShardException =>
        throw e
     }
  }
}<commit_msg>"Connection <foo> is closed" is a normal error in the new querulous world.<commit_after>package com.twitter.gizzard.proxy

import java.sql.SQLException
import shards.ShardId
import scala.reflect.Manifest
import com.twitter.querulous.database.SqlDatabaseTimeoutException
import com.twitter.querulous.query.SqlQueryTimeoutException
import com.twitter.querulous.evaluator.{QueryEvaluator, QueryEvaluatorProxy}


class SqlExceptionWrappingProxy(shardId: ShardId) extends ExceptionHandlingProxy({e =>
  e match {
    case e: SqlQueryTimeoutException =>
      throw new shards.ShardTimeoutException(e.timeout, shardId, e)
    case e: SqlDatabaseTimeoutException =>
      throw new shards.ShardDatabaseTimeoutException(e.timeout, shardId, e)
    case e: SQLException =>
      if ((e.toString contains "Connection") && (e.toString contains " is closed")) {
        throw new shards.NormalShardException(e.toString, shardId, null)
      } else {
        throw new shards.ShardException(e.toString, e)
      }
    case e: shards.ShardException =>
      throw e
  }
})

class ShardExceptionWrappingQueryEvaluator(shardId: ShardId, evaluator: QueryEvaluator) extends QueryEvaluatorProxy(evaluator) {
  override protected def delegate[A](f: => A) = {
    try {
      f
    } catch {
      case e: SqlQueryTimeoutException =>
        throw new shards.ShardTimeoutException(e.timeout, shardId, e)
      case e: SqlDatabaseTimeoutException =>
        throw new shards.ShardDatabaseTimeoutException(e.timeout, shardId, e)
      case e: SQLException =>
        if ((e.toString contains "Connection") && (e.toString contains " is closed")) {
          throw new shards.NormalShardException(e.toString, shardId, null)
        } else {
          throw new shards.ShardException(e.toString, e)
        }
      case e: shards.ShardException =>
        throw e
     }
  }
}
{'fraction_non_alphanumeric': 0.08984973934375959, 'fraction_numerical': 0.0, 'mean_word_length': 3.8254437869822486, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 24, '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': '5013949', 'n_tokens_mistral': 963, 'n_tokens_neox': 967, 'n_words': 226}