Add specific exception for project list file read failure
Add specific exception for project list file read failure

--- a/include/controller/Controller_Message.class.php
+++ b/include/controller/Controller_Message.class.php
@@ -220,6 +220,12 @@
 			return sprintf('%1$s is not a git repository', $exception->Repository);
 		}
 
+		if ($exception instanceof GitPHP_ProjectListFileReadException) {
+			if ($this->resource)
+				return sprintf($this->resource->translate('Failed to open project list file %1$s'), $exception->File);
+			return sprintf('Failed to open project list file %1$s', $exception->File);
+		}
+
 		return $exception->getMessage();
 	}
 

--- /dev/null
+++ b/include/exception/ProjectListFileReadException.class.php
@@ -1,1 +1,34 @@
+<?php
+/** 
+ * Custom exception when a project list file cannot be read
+ *
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2012 Christopher Han
+ * @package GitPHP
+ * @subpackage Exception
+ */
+class GitPHP_ProjectListFileReadException extends GitPHP_MessageException
+{
+	/**
+	 * File
+	 *
+	 * @var string
+	 */
+	public $File;
 
+	/**
+	 * Constructor
+	 *
+	 * @param string $file file
+	 * @param string $message message
+	 * @param int $code exception code
+	 */
+	public function __construct($file, $message = '', $code = 0)
+	{
+		$this->File = $file;
+		if (empty($message))
+			$message = sprintf('Failed to open project list file %1$s', $file);
+		parent::__construct($message, true, 500, $code);
+	}
+}
+

--- a/include/git/projectlist/ProjectListFile.class.php
+++ b/include/git/projectlist/ProjectListFile.class.php
@@ -120,7 +120,7 @@
 		$fileString = file_get_contents($this->projectConfig);
 		
 		if ($fileString === false) {
-			throw new GitPHP_MessageException(sprintf(__('Failed to open project list file %1$s'), $this->projectConfig));
+			throw new GitPHP_ProjectListFileReadException($this->projectConfig);
 		}
 
 		$this->fileContents = array();

comments