<commit_before>module RSpec
  module Expectations
    # @private
    class FailureAggregator
      attr_reader :block_label, :metadata

      def aggregate
        RSpec::Support.with_failure_notifier(self) do
          begin
            yield
          rescue ExpectationNotMetError => e
            failures << e
          rescue Exception => e
            other_errors << e
          end
        end

        notify_aggregated_failures
      end

      def failures
        @failures ||= []
      end

      def other_errors
        @other_errors ||= []
      end

      # This method is defined to satisfy the callable interface
      # expected by `RSpec::Support.with_failure_notifier`.
      def call(failure)
        failure.set_backtrace(caller) unless failure.backtrace
        failures << failure<commit_msg>Add explanatory comments for the odd rescues.<commit_after>module RSpec
  module Expectations
    # @private
    class FailureAggregator
      attr_reader :block_label, :metadata

      def aggregate
        RSpec::Support.with_failure_notifier(self) do
          begin
            yield
          rescue ExpectationNotMetError => e
            # Normally, expectation failures will be notified via the `call` method, below,
            # but since the failure notifier uses a thread local variable, failing expectations
            # in another thread will still raise. We handle that here and categorize it as part
            # of `failures` rather than letting it fall through and be categorized as part of
            # `other_errors`.
            failures << e
          rescue Exception => e
            # While it is normally a bad practice to rescue `Exception`, it's important we do
            # so here. It's low risk (`notify_aggregated_failures` below will re-raise the exception,
            # or raise a `MultipleExpectationsNotMetError` that includes the exception), and it's
            # essential that the user is notified of expectation failures that may have already
            # occurred in the `aggregate_failures` block. Those expectation failures may provide
            # important diagnostics for understanding why this exception occurred, and if simply
            # allowed this exception to be raised as-is, it would (wrongly) suggest to the user
            # that the expectation passed when it did not, which would be quite confusing.
            other_errors << e
          end
        end

        notify_aggregated_failures
      end

      def failures
        @failures ||= []
      end

      def other_errors
        @other_errors ||= []
      end

      # This method is defined to satisfy the callable interface
      # expected by `RSpec::Support.with_failure_notifier`.
      def call(failure)
        failure.set_backtrace(caller) unless failure.backtrace
        failures << failure
{'fraction_non_alphanumeric': 0.05265005265005265, 'fraction_numerical': 0.0, 'mean_word_length': 2.1914893617021276, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '2391919', 'n_tokens_mistral': 690, 'n_tokens_neox': 672, 'n_words': 268}