Commit 9b35263d authored by Robert Lyon's avatar Robert Lyon

Bug 1855771: Allow generic system errors to give more detail

So that we can debug things easier

The Exception class has two useful methods, getFile() and getLine()
so we can use these to dispaly where the problem is rather than just
a generic:  exception(object(ParseError)) at Unknown:0

To test:
- a syntax mistake - add a log_debug() line before the first function in a class
and see if the error shows the correct file/line
- MaharaException - add the following line somewher ein the code
  throw new MaharaException("Missing bananas");
and see if the error shows the correct file/line

behatnotneeded

Change-Id: I5a254f842ab6444ebb324e11e2c93d1c44e3e1d3
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent e9f8e247
......@@ -81,6 +81,7 @@ $string['invaliddirection'] = 'Invalid direction %s.';
$string['onlyoneprofileviewallowed'] = 'You are only allowed one profile page.';
$string['cannotputblocktypeintoview'] = 'Cannot put %s block types into this page';
$string['onlyoneblocktypeperview'] = 'Cannot put more than one %s block type into a page.';
$string['errorat'] = ' at ';
// if you change these next two , be sure to change them in libroot/errors.php
// as they are duplicated there, in the case that get_string was not available.
......
......@@ -533,14 +533,14 @@ function error ($code, $message, $file, $line, $vars) {
function exception ($e) {
$classname = get_class($e);
if (!($e instanceof MaharaException)) {
$e = new SystemException("[{$classname}]: " . $e->getMessage(), $e->getCode());
$e = new SystemException("[{$classname}]: " . $e->getMessage() . get_string('errorat', 'error') . $e->getFile() . ':' . $e->getLine(), $e->getCode());
}
else if ($classname == 'MaharaException') {
// Mahara coding practice says not to use MaharaException directly, but for more
// graceful error handling we have chosen not to make it abstract. Instead, make
// it print like a SystemException.
/* @var MaharaException $e */
$e = new SystemException($e->getMessage(), $e->getCode());
$e = new SystemException($e->getMessage() . get_string('errorat', 'error') . $e->getFile() . ':' . $e->getLine(), $e->getCode());
}
// Display the message and die
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment