Add specific exception for missing projectroot config
Add specific exception for missing projectroot config

--- a/include/controller/Controller_Message.class.php
+++ b/include/controller/Controller_Message.class.php
@@ -190,6 +190,12 @@
 			return sprintf('Could not run the git executable "%1$s".  You may need to set the "%2$s" config value.', $exception->Executable, 'gitbin');
 		}
 
+		if ($exception instanceof GitPHP_MissingProjectrootException) {
+			if ($this->resource)
+				return $this->resource->translate('A projectroot must be set in the config');
+			return 'A projectroot must be set in the config';
+		}
+
 		return $exception->getMessage();
 	}
 

--- /dev/null
+++ b/include/exception/MissingProjectrootException.class.php
@@ -1,1 +1,25 @@
+<?php
+/**
+ * Custom exception when projectroot is missing
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Exception
+ */
+class GitPHP_MissingProjectrootException extends GitPHP_MessageException
+{
+	/**
+	 * Constructor
+	 *
+	 * @param string $message
+	 * @param int $code exception code
+	 */
+	public function __construct($message = '', $code = 0)
+	{
+		if (empty($message))
+			$message = 'A projectroot must be set in the config';
+		parent::__construct($message, true, 500, $code);
+	}
+}
 

--- a/include/git/projectlist/ProjectListBase.class.php
+++ b/include/git/projectlist/ProjectListBase.class.php
@@ -110,7 +110,7 @@
 		$this->projects = array();
 		$this->projectRoot = GitPHP_Util::AddSlash($projectRoot);
 		if (empty($this->projectRoot)) {
-			throw new GitPHP_MessageException(__('A projectroot must be set in the config'), true, 500);
+			throw new GitPHP_MissingProjectrootException();
 		}
 		if (!is_dir($this->projectRoot)) {
 			throw new GitPHP_MessageException(sprintf(__('%1$s is not a directory'), $this->projectRoot), true, 500);

comments