<commit_before><?php
	namespace Bolt;

	class Handler
	{
		public static function error($level, $message, $file, $line, $context)
		{
			throw new Exceptions\Error($message, 0, $level, $file, $line);
		}

		public static function exception($exception)
		{
			$response = new Api\Response();
			$className = get_class($exception);

			error_log($exception->getMessage());

			if (DEPLOYMENT == "production")
			{
				$data = $className;
			}
			else
			{
				$data = array(
					"type" => $className,
					"message" => $exception->getMessage(),
					"code" => $exception->getCode(),
					"line" => $exception->getLine(),
					"file" => $exception->getFile(),
					"trace" => $exception->getTrace()
				);
			}

			$response->status(500, $data);
		}
	}
?><commit_msg>Correctly deal with exceptions when running from CLI<commit_after><?php
	namespace Bolt;

	class Handler
	{
		public static function error($level, $message, $file, $line, $context)
		{
			throw new Exceptions\Error($message, 0, $level, $file, $line);
		}

		public static function exception($exception)
		{
			$className = get_class($exception);

			if (DEPLOYMENT == "production")
			{
				$data = $className;
			}
			else
			{
				$data = array(
					"type" => $className,
					"message" => $exception->getMessage(),
					"code" => $exception->getCode(),
					"line" => $exception->getLine(),
					"file" => $exception->getFile(),
					"trace" => $exception->getTrace()
				);
			}

			if (php_sapi_name() == "cli")
			{
				if (!is_string($data))
				{
					$data = json_encode($data, JSON_PRETTY_PRINT);
				}

				echo($data . "\n");
			}
			else
			{
				$response = new Api\Response();
				$response->status(500, $data);
			}

			die();
		}
	}
?>
{'fraction_non_alphanumeric': 0.18277066356228172, 'fraction_numerical': 0.004656577415599534, 'mean_word_length': 3.006993006993007, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '1626264', 'n_tokens_mistral': 746, 'n_tokens_neox': 577, 'n_words': 122}