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;