Commit 6781785e534de001ce4ca0b70f2a591b70460b13

Authored by Neil Blakey-Milner
1 parent 4749ccf0

On init errors, use an ErrorDispatcher which tries to pretty-print the

error message.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4923 c91229c3-7414-0410-bfa2-8a42b809f60b
config/dmsDefaults.php
... ... @@ -265,8 +265,10 @@ class KTInit {
265 265 if ($checkup === true) {
266 266 return;
267 267 }
268   - // XXX: Make it look pretty
269   - die($oError->toString());
  268 + require_once(KT_LIB_DIR . '/dispatcher.inc.php');
  269 + $oDispatcher =& new KTErrorDispatcher($oError);
  270 + $oDispatcher->dispatch();
  271 + exit(0);
270 272 }
271 273 // }}}
272 274  
... ...
lib/dispatcher.inc.php
... ... @@ -276,5 +276,23 @@ class KTAdminDispatcher extends KTStandardDispatcher {
276 276 }
277 277 }
278 278  
  279 +class KTErrorDispatcher extends KTStandardDispatcher {
  280 + var $bLogonRequired = true;
  281 +
  282 + function KTErrorDispatcher($oError) {
  283 + parent::KTStandardDispatcher();
  284 + $this->oError =& $oError;
  285 + }
  286 +
  287 + function dispatch() {
  288 + require_once(KT_LIB_DIR . '/validation/errorviewer.inc.php');
  289 + $oRegistry =& KTErrorViewerRegistry::getSingleton();
  290 + $oViewer =& $oRegistry->getViewer($this->oError);
  291 + $this->oPage->setTitle($oViewer->view());
  292 + $this->oPage->hideSection();
  293 + $this->handleOutput($oViewer->page());
  294 + }
  295 +}
  296 +
279 297  
280 298 ?>
... ...
lib/validation/errorviewer.inc.php
... ... @@ -13,11 +13,11 @@ class KTErrorViewerRegistry {
13 13 }
14 14  
15 15 function register($sViewerClassName, $sHandledClass) {
16   - $this->aViewers[$sHandledClass] = $sViewerClassName;
  16 + $this->aViewers[strtolower($sHandledClass)] = $sViewerClassName;
17 17 }
18 18  
19 19 function getViewer($oError) {
20   - $sErrorClass = get_class($oError);
  20 + $sErrorClass = strtolower(get_class($oError));
21 21  
22 22 // Try for direct hit first
23 23 $sClass = $sErrorClass;
... ... @@ -77,14 +77,56 @@ class KTErrorViewer {
77 77 }
78 78  
79 79 function viewFull() {
80   - return $this->oError->getString();
  80 + return $this->oError->toString();
  81 + }
  82 +
  83 + function page() {
  84 + $ret = "<h2>Error</h2>\n\n";
  85 + $ret .= "<dl>\n";
  86 + $ret .= "\t<dt>Error type</dt>\n";
  87 + $ret .= "\t<dd>" . $this->oError->getMessage() . "</dd>\n";
  88 + $sInfo = $this->parseUserInfo();
  89 + if ($sInfo) {
  90 + $ret .= "\t<dt>Additional information</dt>\n";
  91 + $ret .= "\t<dd>" . $sInfo . "</dd>\n";
  92 + }
  93 + $ret .= "</dl>\n";
  94 + return $ret;
  95 + }
  96 +
  97 + function parseUserInfo() {
  98 + $sUserInfo = $this->oError->getUserInfo();
  99 + return $sUserInfo;
81 100 }
82 101 }
83 102 $oEVRegistry->register("KTErrorViewer", "PEAR_Error");
84 103  
85 104 class KTDBErrorViewer extends KTErrorViewer {
86 105 function view() {
87   - return _("Database error:") . " " . $this->oError->errorMessage();
  106 + return _("Database error:") . " " . $this->oError->getMessage();
  107 + }
  108 +
  109 + function page() {
  110 + $ret = "<h2>Database Error</h2>\n\n";
  111 + $ret .= "<dl>\n";
  112 + $ret .= "\t<dt>Error type</dt>\n";
  113 + $ret .= "\t<dd>" . $this->oError->getMessage() . "</dd>\n";
  114 + $sInfo = $this->parseUserInfo();
  115 + if ($sInfo) {
  116 + $ret .= "\t<dt>Additional information</dt>\n";
  117 + $ret .= "\t<dd>" . $sInfo . "</dd>\n";
  118 + }
  119 + $ret .= "</dl>\n";
  120 + return $ret;
  121 + }
  122 +
  123 + function parseUserInfo() {
  124 + $sUserInfo = $this->oError->getUserInfo();
  125 + $aMatches = array();
  126 + if (preg_match("#^ ?\[nativecode=(Can't connect to local.*) \(13\)#", $sUserInfo, $aMatches)) {
  127 + return $aMatches[1];
  128 + }
  129 + return $sUserInfo;
88 130 }
89 131 }
90 132 $oEVRegistry->register("KTDBErrorViewer", "DB_Error");
... ...