<commit_before><?php
/* omega - PHP server
   https://github.com/jfillmore/Omega-API-Engine
  
   Copyright 2011, <NAME>
   Licensed under the MIT license. See LICENSE file.
   http://www.opensource.org/licenses/mit-license.php */


class OmegaException extends Exception {
    public $data = null;
    public $comment = null;
    private $args;

    public function __construct($message, $data = null, $args = null) {
        global $om;
        parent::__construct($message);
        $this->data = $data;
        if ($args === null) {
            $args = array();
        }
        $this->args = $args;
        $this->generate_report();
        if (isset($args['email'])) {
            mail($args['email'], $this->subject, $this->body);
            if (isset($args['email_bcc'])) {
                mail($args['email_bcc'], $this->subject, $this->body);
            }
        }
        if (isset($args['alert']) && $args['alert']) {
            // TODO: change e-mail keys to something more predictable (e.g. omega.admin)
            $admin_email = $om->config->get('admin.email');
            mail($admin_email, $this->subject, $this->body);
            $babysitter_email = $om->config->get('admin.babysitter_email');
            if ($babysitter_email != $admin_email) {
                mail($babysitter_email, $this->subject, $this->body);
            }
        }
        if (isset($args['comment'])) {
            $this->comment = $args['comment'];
        }
    }

    private function generate_report() {
        global $om;
        $message = $this->getMessage();
        $email_body = "The following exception was thrown by " . $om->service_name . ' (' . $om->whoami() . ") during API '" . $om->request->get_api() . "': $message\n\n";
        $email_body .= "Back trace:\n";
        $bt_lines = $om->_clean_trace($this->getTrace());
        // get rid of parts of the trace we don't need
        array_pop($bt_lines);
        array_pop($bt_lines);
        array_pop($bt_lines);
        $email_body .= implode("\n", $bt_lines);
        if ($this->comment !== null) {
            $email_boxy .= "\nError Comment:\n$comment\n";
        }
        //$email_body .= "\nGET:\n" . var_export($_GET, true) . "\n";
        //$email_body .= "\nPOST:\n" . var_export($_POST, true) . "\n";
        if ($this->data !== null) {
            if (! is_array($this->data)) {
                $this->data = array($this->data);
            }
            $email_body .= "\n\nOBJECTS:\n===============================\n";
            foreach ($this->data as $i => $obj) {
                $email_body .= "[$i]\n";
                $email_body .= var_export($obj, true) . "\n";
                $email_body .= "-------------------------------\n";
            }
        }
        $this->subject = $om->service_name . ' (' . $om->whoami() . ') Exception: ' . $message;
        $this->body = $email_body;
    }
}

?>
<commit_msg>don't error out if  isn't in use<commit_after><?php
/* omega - PHP server
   https://github.com/jfillmore/Omega-API-Engine
  
   Copyright 2011, <NAME>
   Licensed under the MIT license. See LICENSE file.
   http://www.opensource.org/licenses/mit-license.php */


class OmegaException extends Exception {
    public $data = null;
    public $comment = null;
    private $args;

    public function __construct($message, $data = null, $args = null) {
        global $om;
        parent::__construct($message);
        $this->data = $data;
        if ($args === null) {
            $args = array();
        }
        $this->args = $args;
        $this->generate_report();
        if (isset($args['email'])) {
            mail($args['email'], $this->subject, $this->body);
            if (isset($args['email_bcc'])) {
                mail($args['email_bcc'], $this->subject, $this->body);
            }
        }
        if (isset($args['alert']) && $args['alert']) {
            // TODO: change e-mail keys to something more predictable (e.g. omega.admin)
            $admin_email = $om->config->get('admin.email');
            mail($admin_email, $this->subject, $this->body);
            $babysitter_email = $om->config->get('admin.babysitter_email');
            if ($babysitter_email != $admin_email) {
                mail($babysitter_email, $this->subject, $this->body);
            }
        }
        if (isset($args['comment'])) {
            $this->comment = $args['comment'];
        }
    }

    private function generate_report() {
        global $om;
        $message = $this->getMessage();
        if (isset($om->service_name) && isset($om->whoami)) {
            $email_body = "The following exception was thrown by " . $om->service_name . ' (' . $om->whoami() . ") during API '" . $om->request->get_api() . "': $message\n\n";
        } else {
            $email_body = 'Exception: ';
        }
        $email_body .= "Back trace:\n";
        if (isset($om->_clean_trace)) {
            $bt_lines = $om->_clean_trace($this->getTrace());
            // get rid of parts of the trace we don't need
            array_pop($bt_lines);
            array_pop($bt_lines);
            array_pop($bt_lines);
            $email_body .= implode("\n", $bt_lines);
        }
        if ($this->comment !== null) {
            $email_boxy .= "\nError Comment:\n$comment\n";
        }
        //$email_body .= "\nGET:\n" . var_export($_GET, true) . "\n";
        //$email_body .= "\nPOST:\n" . var_export($_POST, true) . "\n";
        if ($this->data !== null) {
            if (! is_array($this->data)) {
                $this->data = array($this->data);
            }
            $email_body .= "\n\nOBJECTS:\n===============================\n";
            foreach ($this->data as $i => $obj) {
                $email_body .= "[$i]\n";
                $email_body .= var_export($obj, true) . "\n";
                $email_body .= "-------------------------------\n";
            }
        }
        if (isset($om->service_name) && isset($om->whoami)) {
            $this->subject = $om->service_name . ' (' . $om->whoami() . ') Exception: ' . $message;
        } else {
            $this->subject = 'Exception: ' . $message;
        }
        $this->body = $email_body;
    }
}

?>

{'fraction_non_alphanumeric': 0.20090512364635527, 'fraction_numerical': 0.0012930337805075157, 'mean_word_length': 1.8502994011976048, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 81, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '3424173', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1849, 'n_words': 371}