<commit_before>class NoBrainer::QueryRunner::WriteError < NoBrainer::QueryRunner::Middleware
  def call(env)
    @runner.call(env).tap do |result|
      # TODO Fix rethinkdb driver: Their classes Term, Query, Response are
      # not scoped to the RethinkDB module! (that would prevent a user from
      # creating a Response model for example).

      q = env[:query]
      if q.body.type.in?([Term::TermType::UPDATE,
                          Term::TermType::DELETE,
                          Term::TermType::REPLACE,
                          Term::TermType::INSERT])
        if result['errors'] || result['skipped']
          error_msg = "Non existant document" if result['skipped']
          error_msg = "#{result['first_error']}" if result['first_error']
          error_msg += "\nQuery was: #{q.inspect[0..1000]}"
          raise NoBrainer::Error::DocumentNotSaved, error_msg
        end
      end
    end
  end
end
<commit_msg>Fix error checking for rethinkdb 1.5<commit_after>class NoBrainer::QueryRunner::WriteError < NoBrainer::QueryRunner::Middleware
  def call(env)
    @runner.call(env).tap do |result|
      # TODO Fix rethinkdb driver: Their classes Term, Query, Response are
      # not scoped to the RethinkDB module! (that would prevent a user from
      # creating a Response model for example).

      q = env[:query]
      if q.body.type.in?([Term::TermType::UPDATE,
                          Term::TermType::DELETE,
                          Term::TermType::REPLACE,
                          Term::TermType::INSERT])

        if result['errors'].to_i != 0 || result['skipped'].to_i != 0
          error_msg = "Non existant document" if result['skipped'].to_i != 0
          error_msg = "#{result['first_error']}" if result['first_error']
          error_msg += "\nQuery was: #{q.inspect[0..1000]}"
          raise NoBrainer::Error::DocumentNotSaved, error_msg
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12162162162162163, 'fraction_numerical': 0.007796257796257797, 'mean_word_length': 2.4560143626570916, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5096494', 'n_tokens_mistral': 566, 'n_tokens_neox': 558, 'n_words': 144}