<commit_before><?php
namespace Config;
class RouteOutput {
    private $router;
    private $dice;
    private $request;
    private $viewData = [];
    private $errorRoute;
    private $defaultModule;

    public function __construct(\Level2\Router\Router $router, Environment $environment, \Level2\Router\Route $errorRoute,
        \Utils\Request $request,
        $defaultModule = "index") {
        $this->router = $router;
        $this->environment = $environment;
        $this->errorRoute = $errorRoute;
        $this->request = $request;
        $this->defaultModule = $defaultModule;
    }

    public function find(array $url = []) {
        $route = $this->getRoute($url);

        if (empty($route->getView())) return;

        $output = $this->addViewData([
            'model' => $route->getModel(),
            'url' => $url,
            'params' => $this->request->get('url')
        ]);

        return $route->getView()->output($this->viewData);
    }

    public function sendHeaders(array $headers) {
        foreach ($headers as list($name, $content)) {
            if ($name === 'status') http_response_code($content);
            else if ($name === 'location' && $content[0] !== '.')
                header($name . ': ' . $this->environment->getRoot() . $content);
            else header($name . ': ' . $content);
        }
    }

    private function getRoute($url, $tryagain = true) {
        try {
            $route = $this->router->find($url);
        }
        catch (\Exception $e) {
            if ($tryagain) {
                array_unshift($url, $this->defaultModule);
                return $this->getRoute($url, false);
            }

            if ($this->environment->getDebug()) var_dump($e);
            // If there is no route
            $route = $this->errorRoute;
        }

        return $route;
    }

    public function addViewData(array $data) {
        $this->viewData = array_merge_recursive($this->viewData, $data);
    }
}<commit_msg>Add better debug error reporting<commit_after><?php
namespace Config;
class RouteOutput {
    private $router;
    private $dice;
    private $request;
    private $viewData = [];
    private $errorRoute;
    private $defaultModule;
    private $error = null;

    public function __construct(\Level2\Router\Router $router, Environment $environment, \Level2\Router\Route $errorRoute,
                                \Utils\Request $request, $defaultModule = "index") {
        $this->router = $router;
        $this->environment = $environment;
        $this->errorRoute = $errorRoute;
        $this->request = $request;
        $this->defaultModule = $defaultModule;
    }

    public function find(array $url = []) {
        $route = $this->getRoute($url);

        if (empty($route->getView())) return;

        $output = $this->addViewData([
            'model' => $route->getModel(),
            'url' => $url,
            'params' => $this->request->get('url')
        ]);

        return $route->getView()->output($this->viewData);
    }

    public function sendHeaders(array $headers) {
        foreach ($headers as list($name, $content)) {
            if ($name === 'status') http_response_code($content);
            else if ($name === 'location' && $content[0] !== '.' && strpos($content,'http') === false)
                header($name . ': ' . $this->environment->getRoot() . $content);
            else header($name . ': ' . $content);
        }
    }

    private function getRoute($url, $tryagain = true) {
        try {
            $route = $this->router->find($url);
        }
        catch (\Exception $e) {
            if ($this->error === null) $this->error = $e;
            if ($tryagain) {
                array_unshift($url, $this->defaultModule);
                return $this->getRoute($url, false);
            }

            if ($this->environment->getDebug()) var_dump($this->error);
            // If there is no route
            $route = $this->errorRoute;
        }

        return $route;
    }

    public function addViewData(array $data) {
        $this->viewData = array_merge_recursive($this->viewData, $data);
    }
}
{'fraction_non_alphanumeric': 0.1605980226669882, 'fraction_numerical': 0.0014468290330359296, 'mean_word_length': 2.1024682124158565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, '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': '2811274', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1146, 'n_words': 252}