<commit_before><?
/**
 * @version    $Id$
 * @author     <NAME>
 * @package    hunch.ab
 * @subpackage base
 */

/**
 * Content Daemon base exception, thrown by anything related to contentd
 *
 * @package    hunch.ab
 * @subpackage base
 */
class ABException extends Exception
{	
	/**
	 * @param  int
	 * @param  string
	 * @param  string
	 * @param  int
	 */
	public function __construct($msg = null, $errno = 0, $file = null, $line = -1)
	{	
		if($msg instanceof Exception) {
			$line = $msg->getLine();
			$file = $msg->getFile();
			$errno = $msg->getCode();
			$msg = $msg->getMessage();
		}
		parent::__construct($msg, $errno);
		if($file != null) $this->file = $file;
		if($line != -1)   $this->line = $line;
	}
	
	/**
	 * @param  string
	 * @return void
	 */
	public function setMessage($msg) { $this->message = $msg; }
	
	/**
	 * @param  string
	 * @return void
	 */
	public function setFile($msg) { $this->file = $file; }
	
	/**
	 * @param  int
	 * @return void
	 */
	public function setLine($msg) { $this->line = intval($line); }
	
	/**
	 * Render a full HTML description of an exception
	 *
	 * @param  Exception
	 * @param  bool       Include call trace in the output
	 * @param  bool       Return nicely formatted HTML instead of plain text
	 * @param  string[]   An array of function (or Class::method) names to remove from trace 
	 *                    prior to rendering it. Specify null to disable.
	 *                    See {@link formatTrace()} for more information.
	 * @return string
	 * @see    formatTrace()
	 */
	public static function format( Exception $e, $includingTrace = true, $html = true, $skip = null )
	{
		$file = Utils::relativePath($e->getFile(), AB::$basedir);
		if($file{0} != '/')
			$file = '/'.$file;
		
		if($html)
		{
			$str = '<div class="exception"><b>' .  get_class($e) . '</b><br /> '
				. '<span class="message">'.nl2br(htmlentities($e->getMessage())).'</span> '
				. '<span class="file">on line '.$e->getLine()
				. ' in '.$file."</span>";
		}
		else {
			$str = get_class($e) . ': ' . $e->getMessage() . ' on line ' . $e->getLine()
				. ' in ' . $file;<commit_msg>Added extended support for PDOExceptions in ABException::format, including errorInfo data in output.<commit_after><?
/**
 * @version    $Id$
 * @author     <NAME>
 * @package    hunch.ab
 * @subpackage base
 */

/**
 * Content Daemon base exception, thrown by anything related to contentd
 *
 * @package    hunch.ab
 * @subpackage base
 */
class ABException extends Exception
{	
	/**
	 * @param  int
	 * @param  string
	 * @param  string
	 * @param  int
	 */
	public function __construct($msg = null, $errno = 0, $file = null, $line = -1)
	{	
		if($msg instanceof Exception) {
			$line = $msg->getLine();
			$file = $msg->getFile();
			$errno = $msg->getCode();
			$msg = $msg->getMessage();
		}
		parent::__construct($msg, $errno);
		if($file != null) $this->file = $file;
		if($line != -1)   $this->line = $line;
	}
	
	/**
	 * @param  string
	 * @return void
	 */
	public function setMessage($msg) { $this->message = $msg; }
	
	/**
	 * @param  string
	 * @return void
	 */
	public function setFile($msg) { $this->file = $file; }
	
	/**
	 * @param  int
	 * @return void
	 */
	public function setLine($msg) { $this->line = intval($line); }
	
	/**
	 * Render a full HTML description of an exception
	 *
	 * @param  Exception
	 * @param  bool       Include call trace in the output
	 * @param  bool       Return nicely formatted HTML instead of plain text
	 * @param  string[]   An array of function (or Class::method) names to remove from trace 
	 *                    prior to rendering it. Specify null to disable.
	 *                    See {@link formatTrace()} for more information.
	 * @return string
	 * @see    formatTrace()
	 */
	public static function format( Exception $e, $includingTrace = true, $html = true, $skip = null )
	{
		$file = Utils::relativePath($e->getFile(), AB::$basedir);
		if($file{0} != '/')
			$file = '/'.$file;
		
		if($html)
		{
			$str = '<div class="exception"><b>' .  get_class($e) . '</b><br /> '
				. '<span class="message">'.nl2br(htmlentities($e->getMessage()));
			
			if($e instanceof PDOException)
				$str .= '<pre>' . trim(htmlentities($e->errorInfo)).'</pre>';
			
			$str .= '</span> '
				. '<span class="file">on line '.$e->getLine()
				. ' in '.$file."</span>";
		}
		else {
			$str = get_class($e) . ': ' . $e->getMessage();
			
			if($e instanceof PDOException)
				$str .= "\n".trim($e->errorInfo)."\n";
			
			$str .= ' on line ' . $e->getLine() . ' in ' . $file;
{'fraction_non_alphanumeric': 0.183920704845815, 'fraction_numerical': 0.0022026431718061676, 'mean_word_length': 2.6680129240710824, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 53, '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': '4792759', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1483, 'n_words': 410}