<commit_before>class Merb::Dispatcher
  DEFAULT_ERROR_TEMPLATE = File.expand_path(File.dirname(__FILE__) / 'exceptions.html')
  
  class << self
    
    attr_accessor :use_mutex
    
    @@mutex = Mutex.new
    @@work_queue = Queue.new
    
    def work_queue 
      @@work_queue
    end  
    
    Merb::Dispatcher.use_mutex = ::Merb::Config[:use_mutex]
    
    # This is where we grab the incoming request REQUEST_URI and use that in
    # the merb RouteMatcher to determine which controller and method to run.
    # Returns a 2 element tuple of: [controller, action]
    #
    # ControllerExceptions are rescued here and redispatched.
    #
    # ==== Parameters
    # rack_env<Rack::Environment>::
    #   The rack environment, which is used to instantiate a Merb::Request
    # response<IO>::
    #   An IO object to hold the response
    #
    # ==== Returns
    # Array[Merb::Controller, Symbol]::
    #   An array containing the Merb::Controller and the action that was
    #   dispatched to.
    def handle(rack_env)
      start   = Time.now
      request = Merb::Request.new(rack_env)
      Merb.logger.info "Started request handling: #{start.to_s}"
      
      route_index, route_params = Merb::Router.match(request)
      
      if route_params.empty?
        raise ::Merb::ControllerExceptions::NotFound, "No routes match the request: #{request.uri}"
      end
      request.route_params = route_params
      request.params.merge! route_params
            
      controller_name = (route_params[:namespace] ? route_params[:namespace] + '/' : '') + route_params[:controller]
      
      unless controller_name
        raise Merb::ControllerExceptions::NotFound, "Route matched, but route did not specify a controller. Here is what's specified: #{request.route_params.inspect}" 
      end
      
      Merb.logger.debug("Routed to: #{request.route_params.inspect}")

      cnt = controller_name.snake_case.to_const_string
      
      if !Merb::Controller._subclasses.include?(cnt)
        raise Merb::ControllerExceptions::NotFound, "Controller '#{cnt}' not found"
      end
      if cnt == "Application"
        raise Merb::ControllerExceptions::NotFound, "The 'Application' controller has no public actions"
      end

      begin
        klass = Object.full_const_get(cnt)
      rescue NameError => e
        Merb.logger.warn!("Controller class not found: #{e.message}")
        raise Merb::ControllerExceptions::NotFound
      end

      Merb.logger.info("Params: #{klass._filter_params(request.params).inspect}")

      action = route_params[:action]

      if route_index && route = Merb::Router.routes[route_index]
        #Fixate the session ID if it is enabled on the route
        if route.allow_fixation? && request.params.key?(Merb::Controller._session_id_key)
          Merb.logger.info("Fixated session id: #{Merb::Controller._session_id_key}")
          request.cookies[Merb::Controller._session_id_key] = request.params[Merb::Controller._session_id_key]
        end
      end      

      controller = dispatch_action(klass, action, request)
      controller._benchmarks[:dispatch_time] = Time.now - start
      controller.route = route
      Merb.logger.info controller._benchmarks.inspect
      Merb.logger.flush

      controller
    # this is the custom dispatch_exception; it allows failures to still be dispatched
    # to the error controller
    rescue => exception
      Merb.logger.error(Merb.exception(exception))<commit_msg>Log namespaced controller name when it's class is not found.<commit_after>class Merb::Dispatcher
  DEFAULT_ERROR_TEMPLATE = File.expand_path(File.dirname(__FILE__) / 'exceptions.html')
  
  class << self
    
    attr_accessor :use_mutex
    
    @@mutex = Mutex.new
    @@work_queue = Queue.new
    
    def work_queue 
      @@work_queue
    end  
    
    Merb::Dispatcher.use_mutex = ::Merb::Config[:use_mutex]
    
    # This is where we grab the incoming request REQUEST_URI and use that in
    # the merb RouteMatcher to determine which controller and method to run.
    # Returns a 2 element tuple of: [controller, action]
    #
    # ControllerExceptions are rescued here and redispatched.
    #
    # ==== Parameters
    # rack_env<Rack::Environment>::
    #   The rack environment, which is used to instantiate a Merb::Request
    # response<IO>::
    #   An IO object to hold the response
    #
    # ==== Returns
    # Array[Merb::Controller, Symbol]::
    #   An array containing the Merb::Controller and the action that was
    #   dispatched to.
    def handle(rack_env)
      start   = Time.now
      request = Merb::Request.new(rack_env)
      Merb.logger.info "Started request handling: #{start.to_s}"
      
      route_index, route_params = Merb::Router.match(request)
      
      if route_params.empty?
        raise ::Merb::ControllerExceptions::NotFound, "No routes match the request: #{request.uri}"
      end
      request.route_params = route_params
      request.params.merge! route_params
            
      controller_name = (route_params[:namespace] ? route_params[:namespace] + '/' : '') + route_params[:controller]
      
      unless controller_name
        raise Merb::ControllerExceptions::NotFound, "Route matched, but route did not specify a controller. Here is what's specified: #{request.route_params.inspect}" 
      end
      
      Merb.logger.debug("Routed to: #{request.route_params.inspect}")

      cnt = controller_name.snake_case.to_const_string
      
      if !Merb::Controller._subclasses.include?(cnt)
        raise Merb::ControllerExceptions::NotFound, "Controller '#{cnt}' not found"
      end
      if cnt == "Application"
        raise Merb::ControllerExceptions::NotFound, "The 'Application' controller has no public actions"
      end

      begin
        klass = Object.full_const_get(cnt)
      rescue NameError => e
        Merb.logger.warn!("Controller class not found for controller #{controller_name}: #{e.message}")
        raise Merb::ControllerExceptions::NotFound
      end

      Merb.logger.info("Params: #{klass._filter_params(request.params).inspect}")

      action = route_params[:action]

      if route_index && route = Merb::Router.routes[route_index]
        #Fixate the session ID if it is enabled on the route
        if route.allow_fixation? && request.params.key?(Merb::Controller._session_id_key)
          Merb.logger.info("Fixated session id: #{Merb::Controller._session_id_key}")
          request.cookies[Merb::Controller._session_id_key] = request.params[Merb::Controller._session_id_key]
        end
      end      

      controller = dispatch_action(klass, action, request)
      controller._benchmarks[:dispatch_time] = Time.now - start
      controller.route = route
      Merb.logger.info controller._benchmarks.inspect
      Merb.logger.flush

      controller
    # this is the custom dispatch_exception; it allows failures to still be dispatched
    # to the error controller
    rescue => exception
      Merb.logger.error(Merb.exception(exception))
{'fraction_non_alphanumeric': 0.09904517600114009, 'fraction_numerical': 0.0002850220892119139, 'mean_word_length': 3.01487414187643, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6596056', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1989, 'n_words': 505}