<commit_before>package me.prettyprint.cassandra.service;

import java.net.SocketTimeoutException;
import java.util.NoSuchElementException;

import me.prettyprint.hector.api.exceptions.HCassandraInternalException;
import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HTimedOutException;
import me.prettyprint.hector.api.exceptions.HUnavailableException;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.exceptions.HectorTransportException;
import me.prettyprint.hector.api.exceptions.PoolExhaustedException;
import me.prettyprint.hector.api.exceptions.PoolIllegalStateException;

import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.transport.TTransportException;

public final class ExceptionsTranslatorImpl implements ExceptionsTranslator {


  @Override
  public HectorException translate(Throwable original) {
    if (original instanceof HectorException) {
      return (HectorException) original;
    } else if (original instanceof TApplicationException) {
      return new HCassandraInternalException(((TApplicationException)original).getType(), original.getMessage());
    } else if (original instanceof TException) {
      return new HectorTransportException(original);
    } else if (original instanceof TTransportException) {
      // if the underlying cause is a scoket timeout, reflect that directly
      // TODO this may be an issue on the Cassandra side which warrants ivestigation.
      // I seem to remember these coming back as TimedOutException previously
      if ( ((TTransportException)original).getCause() instanceof SocketTimeoutException ) {
        return new HTimedOutException(original);
      } else {
        return new HectorTransportException(original);
      }
    } else if (original instanceof org.apache.cassandra.thrift.TimedOutException) {
      return new HTimedOutException(original);
    } else if (original instanceof org.apache.cassandra.thrift.InvalidRequestException) {
      // See bug https://issues.apache.org/jira/browse/CASSANDRA-1862
      // If a bootstrapping node is accessed it responds with IRE. It makes more sense to throw
      // UnavailableException.
      // Hector wraps this caveat and fixes this.
      String why = ((org.apache.cassandra.thrift.InvalidRequestException) original).getWhy();
      if (why != null && why.contains("bootstrap")) {
        return new HUnavailableException(original);
      }
      HInvalidRequestException e = new HInvalidRequestException(original);
      e.setWhy(why);
      return e;
    } else if (original instanceof PoolExhaustedException ) {
      return (PoolExhaustedException)original;
    } else if (original instanceof TProtocolException) {
      return new HInvalidRequestException(original);
    } else if (original instanceof org.apache.cassandra.thrift.NotFoundException) {
      return new HNotFoundException(original);
    } else if (original instanceof org.apache.cassandra.thrift.UnavailableException) {
      return new HUnavailableException(original);
    } else if (original instanceof NoSuchElementException) {
      return new PoolExhaustedException(original);
    } else if (original instanceof IllegalStateException) {
      return new PoolIllegalStateException(original);
    } else {
      return new HectorException(original);
    }
  }

}<commit_msg>moved check for transport exception to where it will actually do something. Thanks to <NAME> for changes<commit_after>package me.prettyprint.cassandra.service;

import java.net.SocketTimeoutException;
import java.util.NoSuchElementException;

import me.prettyprint.hector.api.exceptions.HCassandraInternalException;
import me.prettyprint.hector.api.exceptions.HInvalidRequestException;
import me.prettyprint.hector.api.exceptions.HNotFoundException;
import me.prettyprint.hector.api.exceptions.HTimedOutException;
import me.prettyprint.hector.api.exceptions.HUnavailableException;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.exceptions.HectorTransportException;
import me.prettyprint.hector.api.exceptions.PoolExhaustedException;
import me.prettyprint.hector.api.exceptions.PoolIllegalStateException;

import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.transport.TTransportException;

public final class ExceptionsTranslatorImpl implements ExceptionsTranslator {


  @Override
  public HectorException translate(Throwable original) {
    if (original instanceof HectorException) {
      return (HectorException) original;
    } else if (original instanceof TApplicationException) {
      return new HCassandraInternalException(((TApplicationException)original).getType(), original.getMessage());    
    } else if (original instanceof TTransportException) {
      // if the underlying cause is a scoket timeout, reflect that directly
      // TODO this may be an issue on the Cassandra side which warrants ivestigation.
      // I seem to remember these coming back as TimedOutException previously
      if ( ((TTransportException)original).getCause() instanceof SocketTimeoutException ) {
        return new HTimedOutException(original);
      } else {
        return new HectorTransportException(original);
      }
    } else if (original instanceof org.apache.cassandra.thrift.TimedOutException) {
      return new HTimedOutException(original);
    } else if (original instanceof org.apache.cassandra.thrift.InvalidRequestException) {
      // See bug https://issues.apache.org/jira/browse/CASSANDRA-1862
      // If a bootstrapping node is accessed it responds with IRE. It makes more sense to throw
      // UnavailableException.
      // Hector wraps this caveat and fixes this.
      String why = ((org.apache.cassandra.thrift.InvalidRequestException) original).getWhy();
      if (why != null && why.contains("bootstrap")) {
        return new HUnavailableException(original);
      }
      HInvalidRequestException e = new HInvalidRequestException(original);
      e.setWhy(why);
      return e;
    } else if (original instanceof PoolExhaustedException ) {
      return (PoolExhaustedException)original;
    } else if (original instanceof TProtocolException) {
      return new HInvalidRequestException(original);
    } else if (original instanceof org.apache.cassandra.thrift.NotFoundException) {
      return new HNotFoundException(original);
    } else if (original instanceof org.apache.cassandra.thrift.UnavailableException) {
      return new HUnavailableException(original);
    } else if (original instanceof TException) {
      return new HectorTransportException(original);
    } else if (original instanceof NoSuchElementException) {
      return new PoolExhaustedException(original);
    } else if (original instanceof IllegalStateException) {
      return new PoolIllegalStateException(original);
    } else {
      return new HectorException(original);
    }
  }

}
{'fraction_non_alphanumeric': 0.08003884033846581, 'fraction_numerical': 0.0011097239561659038, 'mean_word_length': 4.47040971168437, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 2, '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': '7253216', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1870, 'n_words': 468}