Errors/Logging

* log addNotes to DB as php user-errors
  * always skip the native php error handler
This commit is contained in:
Sarjuuk
2015-07-18 16:45:11 +02:00
parent 58a235e2e3
commit 998763be7b
11 changed files with 44 additions and 45 deletions

View File

@@ -190,7 +190,7 @@ class CommunityContent
}
else
{
Util::addNote(U_GROUP_STAFF, 'CommunityClass::getCommentPreviews - comment '.$c['id'].' belongs to nonexistant subject');
Util::logError('Comment '.$c['id'].' belongs to nonexistant subject.', E_USER_NOTICE);
unset($comments[$idx]);
}
}
@@ -341,7 +341,7 @@ class CommunityContent
{
if (empty($p['name']))
{
Util::addNote(U_GROUP_STAFF | U_GROUP_SCREENSHOT, 'AdminPage::handleScreenshots() - Screenshot linked to nonexistant type/typeId combination '.$p['type'].'/'.$p['typeId']);
Util::logError('Screenshot linked to nonexistant type/typeId combination: '.$p['type'].'/'.$p['typeId'], E_USER_NOTICE);
unset($p);
}
else

View File

@@ -73,7 +73,7 @@ foreach ($sets as $k => $v)
// this should not have been possible
if (!strlen($v['value']) && !($v['flags'] & CON_FLAG_TYPE_STRING) && !$php)
{
Util::addNote(U_GROUP_ADMIN | U_GROUP_DEV, 'Kernel: Aowow config value CFG_'.strtoupper($k).' is empty - config will not be used!');
Util::logError('Aowow config value CFG_'.strtoupper($k).' is empty - config will not be used!', E_USER_ERROR);
continue;
}
@@ -87,12 +87,12 @@ foreach ($sets as $k => $v)
$val = preg_replace('/[^\p{L}0-9~\s_\-\'\/\.:,]/ui', '', $v['value']);
else if ($php)
{
Util::addNote(U_GROUP_ADMIN | U_GROUP_DEV, 'Kernel: PHP config value '.strtolower($k).' has no type set - config will not be used!');
Util::logError('PHP config value '.strtolower($k).' has no type set - config will not be used!', E_USER_ERROR);
continue;
}
else // if (!$php)
{
Util::addNote(U_GROUP_ADMIN | U_GROUP_DEV, 'Kernel: Aowow config value CFG_'.strtoupper($k).' has no type set - value forced to 0!');
Util::logError('Aowow config value CFG_'.strtoupper($k).' has no type set - value forced to 0!', E_USER_ERROR);
$val = 0;
}
@@ -105,9 +105,10 @@ foreach ($sets as $k => $v)
// handle occuring errors
error_reporting(!empty($AoWoWconf['aowow']) && CFG_DEBUG ? (E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)) : 0);
$errHandled = false;
set_error_handler(function($errNo, $errStr, $errFile, $errLine) use (&$errHandled) {
set_error_handler(function($errNo, $errStr, $errFile, $errLine) {
$errName = 'unknown error'; // errors not in this list can not be handled by set_error_handler (as per documentation) or are ignored
$uGroup = U_GROUP_EMPLOYEE;
if ($errNo == E_WARNING) // 0x0002
$errName = 'E_WARNING';
else if ($errNo == E_PARSE) // 0x0004
@@ -120,26 +121,18 @@ set_error_handler(function($errNo, $errStr, $errFile, $errLine) use (&$errHandle
$errName = 'E_USER_WARNING';
else if ($errNo == E_USER_NOTICE) // 0x0400
$errName = 'E_USER_NOTICE';
$uGroup = U_GROUP_STAFF;
else if ($errNo == E_RECOVERABLE_ERROR) // 0x1000
$errName = 'E_RECOVERABLE_ERROR';
if (User::isInGroup(U_GROUP_STAFF))
{
if (!$errHandled)
{
Util::addNote(U_GROUP_STAFF, 'one or more php related error occured, while generating this page.');
$errHandled = true;
}
Util::addNote(U_GROUP_STAFF, $errName.' - '.$errStr.' @ '.$errFile. ':'.$errLine);
}
Util::addNote($uGroup, $errName.' - '.$errStr.' @ '.$errFile. ':'.$errLine);
if (DB::isConnectable(DB_AOWOW))
DB::Aowow()->query('INSERT INTO ?_errors (`date`, `version`, `phpError`, `file`, `line`, `query`, `userGroups`, `message`) VALUES (UNIX_TIMESTAMP(), ?d, ?d, ?, ?d, ?, ?d, ?) ON DUPLICATE KEY UPDATE `date` = UNIX_TIMESTAMP()',
AOWOW_REVISION, $errNo, $errFile, $errLine, CLI ? 'CLI' : $_SERVER['QUERY_STRING'], User::$groups, $errStr
);
return !((User::isInGroup(U_GROUP_STAFF) && defined('CFG_DEBUG') && CFG_DEBUG) || CLI);
return true;
}, E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT));
@@ -158,7 +151,7 @@ if (!CLI)
// Setup Session
if (CFG_SESSION_CACHE_DIR && Util::checkOrCreateDirectory(CFG_SESSION_CACHE_DIR))
session_save_path(getcwd().'/'.CFG_SESSION_CACHE_DIR);
session_save_path(CFG_SESSION_CACHE_DIR);
session_set_cookie_params(15 * YEAR, '/', '', $secure, true);
session_cache_limiter('private');

View File

@@ -175,7 +175,7 @@ class Loot
}
else // shouldn't have happened
{
Util::addNote(U_GROUP_EMPLOYEE, 'Loot::getByContainerRecursive: unhandled case in calculating chance for item '.$entry['Item'].'!');
Util::logError('Unhandled case in calculating chance for item '.$entry['Item'].'!');
continue;
}
@@ -189,7 +189,7 @@ class Loot
$sum = 0;
else if ($sum >= 100.01)
{
Util::addNote(U_GROUP_EMPLOYEE, 'Loot::getByContainerRecursive: entry '.$lootId.' / group '.$k.' has a total chance of '.number_format($sum, 2).'%. Some items cannot drop!');
Util::logError('Loot entry '.$lootId.' / group '.$k.' has a total chance of '.number_format($sum, 2).'%. Some items cannot drop!');
$sum = 100;
}
@@ -378,13 +378,13 @@ class Loot
{
// check for possible database inconsistencies
if (!$ref['chance'] && !$ref['isGrouped'])
Util::addNote(U_GROUP_EMPLOYEE, 'Loot by Item: ungrouped Item/Ref '.$ref['item'].' has 0% chance assigned!');
Util::logError('Loot by Item: Ungrouped Item/Ref '.$ref['item'].' has 0% chance assigned!');
if ($ref['isGrouped'] && $ref['sumChance'] > 100)
Util::addNote(U_GROUP_EMPLOYEE, 'Loot by Item: group with Item/Ref '.$ref['item'].' has '.number_format($ref['sumChance'], 2).'% total chance! Some items cannot drop!');
Util::logError('Loot by Item: Group with Item/Ref '.$ref['item'].' has '.number_format($ref['sumChance'], 2).'% total chance! Some items cannot drop!');
if ($ref['isGrouped'] && $ref['sumChance'] >= 100 && !$ref['chance'])
Util::addNote(U_GROUP_EMPLOYEE, 'Loot by Item: Item/Ref '.$ref['item'].' with adaptive chance cannot drop. Group already at 100%!');
Util::logError('Loot by Item: Item/Ref '.$ref['item'].' with adaptive chance cannot drop. Group already at 100%!');
$chance = abs($ref['chance'] ?: (100 - $ref['sumChance']) / $ref['nZeroItems']) / 100;

View File

@@ -698,19 +698,23 @@ class Util
public static $wowheadLink = '';
private static $notes = [];
// creates an announcement; use if minor issues arise
public static function logError($errStr, $mode = E_USER_WARNING)
{
// handled by set_error_handler
trigger_error($errStr, $mode);
}
public static function addNote($uGroupMask, $str)
{
// todo (med): log all those errors to DB
self::$notes[] = [$uGroupMask, $str];
}
public static function getNotes($restricted = true)
public static function getNotes()
{
$notes = [];
foreach (self::$notes as $data)
if (!$restricted || !$data[0] || User::isInGroup($data[0]))
if (!$data[0] || User::isInGroup($data[0]))
$notes[] = $data[1];
return $notes;
@@ -1718,9 +1722,9 @@ class Util
$path = preg_replace('|/+|', '/', $path);
if (!is_dir($path) && !@mkdir($path, self::FILE_ACCESS, true))
self::addNote(U_GROUP_EMPLOYEE, 'could not create directory: '.$path);
self::logError('Could not create directory: '.$path, E_USER_ERROR);
else if (!is_writable($path) && !@chmod($path, self::FILE_ACCESS))
self::addNote(U_GROUP_EMPLOYEE, 'cannot write into directory: '.$path);
self::logError('Cannot write into directory: '.$path, E_USER_ERROR);
else
return true;

View File

@@ -49,7 +49,7 @@ class Lang
{
if (!isset(self::$$prop))
{
Util::addNote(U_GROUP_STAFF, 'Lang::__callStatic() - tried to use undefined property Lang::$'.$prop);
Util::logError('Lang - tried to use undefined property Lang::$'.$prop);
return null;
}
@@ -58,7 +58,7 @@ class Lang
{
if (!isset($var[$key]))
{
Util::addNote(U_GROUP_STAFF, 'Lang::__callStatic() - undefined key "'.$key.'" in property Lang::$'.$prop.'[\''.implode('\'][\'', $args).'\']');
Util::logError('Lang - undefined key "'.$key.'" in property Lang::$'.$prop.'[\''.implode('\'][\'', $args).'\']');
return null;
}
@@ -73,14 +73,14 @@ class Lang
if (!isset(self::$$prop))
{
Util::addNote(U_GROUP_STAFF, 'Lang::sort() - tried to use undefined property Lang::$'.$prop);
Util::logError('Lang::sort - tried to use undefined property Lang::$'.$prop);
return null;
}
$var = &self::$$prop;
if (!isset($var[$group]))
{
Util::addNote(U_GROUP_STAFF, 'Lang::sort() - tried to use undefined property Lang::$'.$prop.'[\''.$group.'\']');
Util::logError('Lang::sort - tried to use undefined property Lang::$'.$prop.'[\''.$group.'\']');
return null;
}

View File

@@ -218,7 +218,7 @@ class EventPage extends GenericPage
if ($v > 0)
$list[] = $v;
else if ($v === null)
Util::addNote(U_GROUP_EMPLOYEE, 'game_event_prerequisite: this event has itself as prerequisite');
Util::logError('game_event_prerequisite: this event has itself as prerequisite');
});
if ($list)

View File

@@ -323,6 +323,8 @@ class GenericPage
// display occured notices
if ($_ = Util::getNotes())
{
array_unshift($_, 'One or more errors occured, while generating this page.');
$this->announcements[0] = array(
'parent' => 'announcement-0',
'id' => 0,

View File

@@ -355,7 +355,7 @@ class ItemPage extends genericPage
}
else
{
Util::addNote(U_GROUP_STAFF, 'Referenced PageTextId #'.$next.' is not in DB');
Util::logError('Referenced PageTextId #'.$next.' is not in DB');
break;
}
}

View File

@@ -509,7 +509,7 @@ class NpcPage extends GenericPage
}
}
else
Util::addNote(U_GROUP_EMPLOYEE, 'NPC '.$this->typeId.' is flagged as trainer, but doesn\'t have any spells set');
Util::logError('NPC '.$this->typeId.' is flagged as trainer, but doesn\'t have any spells set');
}
// tab: sells

View File

@@ -213,7 +213,7 @@ class ObjectPage extends GenericPage
}
else
{
Util::addNote(U_GROUP_STAFF, 'Referenced PageTextId #'.$next.' is not in DB');
Util::logError('Referenced PageTextId #'.$next.' is not in DB');
break;
}
}

View File

@@ -35,7 +35,7 @@ class ScreenshotPage extends GenericPage
if ($this->minSize <= 0)
{
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::__construct() - config error: dimensions for uploaded screenshots egual or less than zero. Value forced to 200');
Util::logError('config error: dimensions for uploaded screenshots equal or less than zero. Value forced to 200');
$this->minSize = 200;
}
@@ -276,26 +276,26 @@ class ScreenshotPage extends GenericPage
switch ($_FILES['screenshotfile']['error'])
{
case 1:
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - the file exceeds the maximum size of '.ini_get('upload_max_filesize'));
Util::logError('validateScreenshot - the file exceeds the maximum size of '.ini_get('upload_max_filesize'));
return Lang::screenshot('error', 'selectSS');
case 3:
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - upload was interrupted');
Util::logError('validateScreenshot - upload was interrupted');
return Lang::screenshot('error', 'selectSS');
case 4:
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - no file was received');
Util::logError('validateScreenshot() - no file was received');
return Lang::screenshot('error', 'selectSS');
case 6:
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - temporary upload directory is not set');
Util::logError('validateScreenshot - temporary upload directory is not set');
return Lang::main('intError');
case 7:
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - could not write temporary file to disk');
Util::logError('validateScreenshot - could not write temporary file to disk');
return Lang::main('intError');
}
// points to invalid file (hack attempt)
if (!is_uploaded_file($_FILES['screenshotfile']['tmp_name']))
{
Util::addNote(U_GROUP_EMPLOYEE, 'ScreenshotPage::validateScreenshot() - uploaded file not in upload directory');
Util::logError('validateScreenshot - uploaded file not in upload directory');
return Lang::main('intError');
}