From: Michael M Slusarz Date: Fri, 23 Jan 2009 17:56:22 +0000 (-0700) Subject: Exception handling in Chora X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=28a4bb38e253fd441f255e3f5908b348aa624efc;p=horde.git Exception handling in Chora --- diff --git a/chora/annotate.php b/chora/annotate.php index 79cee551a..ccf81e9a2 100644 --- a/chora/annotate.php +++ b/chora/annotate.php @@ -12,8 +12,11 @@ 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('%s | %s', diff --git a/chora/browse.php b/chora/browse.php index fa94dbf56..1597d52b0 100644 --- a/chora/browse.php +++ b/chora/browse.php @@ -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(); diff --git a/chora/co.php b/chora/co.php index 7515782ce..8e3fae117 100644 --- a/chora/co.php +++ b/chora/co.php @@ -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); diff --git a/chora/diff.php b/chora/diff.php index 08af32f96..354e914f3 100644 --- a/chora/diff.php +++ b/chora/diff.php @@ -12,8 +12,11 @@ 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. */ diff --git a/chora/history.php b/chora/history.php index e68d3cd68..2f69f741b 100644 --- a/chora/history.php +++ b/chora/history.php @@ -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'); diff --git a/chora/lib/Chora.php b/chora/lib/Chora.php index 42d87c185..e99b8f503 100644 --- a/chora/lib/Chora.php +++ b/chora/lib/Chora.php @@ -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. diff --git a/chora/patchsets.php b/chora/patchsets.php index cb7948036..8b72b009d 100644 --- a/chora/patchsets.php +++ b/chora/patchsets.php @@ -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(); diff --git a/chora/stats.php b/chora/stats.php index f406e3385..f3840ec18 100644 --- a/chora/stats.php +++ b/chora/stats.php @@ -11,8 +11,11 @@ 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();