Exception handling in Chora
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jan 2009 17:56:22 +0000 (10:56 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 23 Jan 2009 17:59:21 +0000 (10:59 -0700)
chora/annotate.php
chora/browse.php
chora/co.php
chora/diff.php
chora/history.php
chora/lib/Chora.php
chora/patchsets.php
chora/stats.php

index 79cee55..ccf81e9 100644 (file)
 require_once dirname(__FILE__) . '/lib/base.php';
 
 /* Spawn the file object. */
-$fl = $VC->getFileObject($where, array('cache' => $cache));
-Chora::checkError($fl);
+try {
+    $fl = $VC->getFileObject($where, array('cache' => $cache));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 $rev_ob = $VC->getRevisionObject();
 
 /* Retrieve the desired revision from the GET variable. */
@@ -34,7 +37,11 @@ case 'log':
 }
 
 $ann = $VC->getAnnotateObject($fl);
-Chora::checkError($lines = $ann->doAnnotate($rev));
+try {
+    $lines = $ann->doAnnotate($rev);
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 
 $title = sprintf(_("Source Annotation of %s (revision %s)"), Text::htmlAllSpaces($where), $rev);
 $extraLink = sprintf('<a href="%s">%s</a> | <a href="%s">%s</a>',
index fa94dbf..1597d52 100644 (file)
@@ -19,13 +19,16 @@ if (!$atdir && !$VC->isFile($fullname)) {
 $rev_ob = $VC->getRevisionObject();
 
 if ($atdir) {
-    Chora::checkError($dir = $VC->queryDir($where));
-
-    $atticFlags = (bool)$acts['sa'];
-    Chora::checkError($dir->browseDir($cache, true, $atticFlags));
-    $dir->applySort($acts['sbt'], $acts['ord']);
-    Chora::checkError($dirList = &$dir->queryDirList());
-    Chora::checkError($fileList = $dir->queryFileList($atticFlags));
+    try {
+        $dir = $VC->queryDir($where);
+        $atticFlags = (bool)$acts['sa'];
+        $dir->browseDir($cache, true, $atticFlags);
+        $dir->applySort($acts['sbt'], $acts['ord']);
+        $dirList = &$dir->queryDirList();
+        $fileList = $dir->queryFileList($atticFlags);
+    } catch (Horde_Vcs_Exception $e) {
+        Chora::fatal($e);
+    }
 
     /* Decide what title to display. */
     $title = ($where == '')
@@ -90,9 +93,6 @@ if ($atdir) {
                 continue;
             }
             $lg = $currFile->queryLastLog();
-            if (is_a($lg, 'PEAR_Error')) {
-                continue;
-            }
             $realname = $currFile->queryName();
             $mimeType = Horde_Mime_Magic::filenameToMIME($realname);
 
@@ -126,8 +126,12 @@ if ($atdir) {
 
 /* Showing a file. */
 $onb = Util::getFormData('onb');
-$fl = $VC->getFileObject($where, array('cache' => $cache, 'branch' => $onb));
-Chora::checkError($fl);
+try {
+    $fl = $VC->getFileObject($where, array('cache' => $cache, 'branch' => $onb));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
+
 $title = sprintf(_("Revisions for %s"), $where);
 
 $extraLink = Chora::getFileViews();
index 7515782..8e3fae1 100644 (file)
@@ -21,8 +21,11 @@ if ($atdir) {
 $plain = Util::getFormData('p', 0);
 
 /* Create the VC_File object and populate it. */
-$file = $VC->getFileObject($where, array('cache' => $cache));
-Chora::checkError($file);
+try {
+    $file = $VC->getFileObject($where, array('cache' => $cache));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 
 /* Get the revision number. */
 $r = Util::getFormData('r');
@@ -42,7 +45,11 @@ if (!$VC->isValidRevision($r)) {
 }
 
 /* Retrieve the actual checkout. */
-$checkOut = $VC->getCheckout($file, $r);
+try {
+    $checkOut = $VC->getCheckout($file, $r);
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 
 /* Get the MIME type of the file, or at least our best guess at it. */
 $mime_type = Horde_Mime_Magic::filenameToMIME($fullname);
@@ -50,10 +57,6 @@ if ($mime_type == 'application/octet-stream') {
     $mime_type = 'text/plain';
 }
 
-/* Check error status, and either show error page, or the checkout
- * contents */
-Chora::checkError($checkOut);
-
 if (!$plain) {
     /* Pretty-print the checked out copy */
     $pretty = Chora::pretty($mime_type, $checkOut);
index 08af32f..354e914 100644 (file)
 require_once dirname(__FILE__) . '/lib/base.php';
 
 /* Spawn the repository and file objects */
-$fl = $VC->getFileObject($where, array('cache' => $cache));
-Chora::checkError($fl);
+try {
+    $fl = $VC->getFileObject($where, array('cache' => $cache));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 $rev_ob = $VC->getRevisionObject();
 
 /* Initialise the form variables correctly. */
index e68d3cd..2f69f74 100644 (file)
@@ -18,8 +18,11 @@ if (!$VC->hasFeature('branches')) {
 }
 
 /* Spawn the file object. */
-$fl = $VC->getFileObject($where, array('cache' => $cache));
-Chora::checkError($fl);
+try {
+    $fl = $VC->getFileObject($where, array('cache' => $cache));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 $rev_ob = $VC->getRevisionObject();
 
 $colset = array('#ccdeff', '#ecf', '#fec', '#efc', '#cfd', '#dcdba0');
index 42d87c1..e99b8f5 100644 (file)
@@ -127,13 +127,14 @@ class Chora
         $sourceroot = $acts['rt'];
 
         $conf['paths']['temp'] = Horde::getTempDir();
-        $GLOBALS['VC'] = Horde_Vcs::factory(String::ucfirst($sourcerootopts['type']),
-            array('sourceroot' => $sourcerootopts['location'],
-                  'paths' => $conf['paths'],
-                  'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '',
-                  'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : ''));
-        if (is_a($GLOBALS['VC'], 'PEAR_Error')) {
-            Chora::fatal($GLOBALS['VC']->getMessage());
+        try {
+            $GLOBALS['VC'] = Horde_Vcs::factory(String::ucfirst($sourcerootopts['type']),
+                array('sourceroot' => $sourcerootopts['location'],
+                      'paths' => $conf['paths'],
+                      'username' => isset($sourcerootopts['username']) ? $sourcerootopts['username'] : '',
+                      'password' => isset($sourcerootopts['password']) ? $sourcerootopts['password'] : ''));
+        } catch (Horde_Vcs_Exception $e) {
+            Chora::fatal($e);
         }
 
         $conf['paths']['sourceroot'] = $sourcerootopts['location'];
@@ -228,6 +229,10 @@ class Chora
 
         global $registry, $conf, $notification, $browser, $prefs;
 
+        if (is_a($message, 'Horde_Vcs_Exception')) {
+            $message = $message->getMessage();
+        }
+
         /* Don't store the bad file in the user's preferences. */
         $prefs->setValue('last_file', '');
 
@@ -243,19 +248,6 @@ class Chora
     }
 
     /**
-     * Given a return object from a Horde_Vcs:: call, make sure
-     * that it's not a PEAR_Error object.
-     *
-     * @param mixed $e  Return object from a Horde_Vcs:: call.
-     */
-    static public function checkError($e)
-    {
-        if (is_a($e, 'PEAR_Error')) {
-            Chora::fatal($e->getMessage());
-        }
-    }
-
-    /**
      * Convert a commit-name into whatever the user wants.
      *
      * @param string $name  Account name.
index cb79480..8b72b00 100644 (file)
@@ -23,8 +23,11 @@ if (!$VC->isFile($fullname)) {
     Chora::fatal(sprintf(_("%s: no such file or directory"), $where), '404 Not Found');
 }
 
-$ps = $VC->getPatchsetObject($where, $cache);
-Chora::checkError($ps);
+try {
+    $ps = $VC->getPatchsetObject($where, $cache);
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 
 $title = sprintf(_("Patchsets for %s"), $where);
 $extraLink = Chora::getFileViews();
index f406e33..f3840ec 100644 (file)
 
 require_once dirname(__FILE__) . '/lib/base.php';
 
-$fl = $VC->getFileObject($where, array('cache' => $cache));
-Chora::checkError($fl);
+try {
+    $fl = $VC->getFileObject($where, array('cache' => $cache));
+} catch (Horde_Vcs_Exception $e) {
+    Chora::fatal($e);
+}
 
 $extraLink = Chora::getFileViews();