From 781a233a9e0bdb95c4d1a40b96358d608e07de0e Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 2 Jul 2024 09:59:46 +0300 Subject: [PATCH] fix: Fix to Line Numbers in Exception Logging --- .../test/cli/SchedulerCommandTest.php | 25 ++++++++++--------- webfiori/framework/scheduler/AbstractTask.php | 10 ++++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php index 7303a559..aeb14d81 100644 --- a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php +++ b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php @@ -172,21 +172,22 @@ public function test05() { "Thrown in: Fail2TestTask\n", "Line: 44\n", "Stack Trace:\n", - "#0 At class app\\tasks\Fail2TestTask line 1083\n", - "#1 At class webfiori\\framework\scheduler\AbstractTask line 406\n", - "#2 At class webfiori\\framework\scheduler\AbstractTask line 903\n", - "#3 At class webfiori\\framework\scheduler\TasksManager line 625\n", - "#4 At class webfiori\\framework\scheduler\TasksManager line 135\n", - "#5 At class webfiori\\framework\cli\commands\SchedulerCommand line 86\n", - "#6 At class webfiori\\framework\cli\commands\SchedulerCommand line 328\n", - "#7 At class webfiori\\cli\CLICommand line 409\n", - "#8 At class webfiori\\cli\Runner line 684\n", - "#9 At class webfiori\\cli\Runner line 615\n", - "#10 At class webfiori\cli\Runner line 154\n", + "#0 At class app\\tasks\Fail2TestTask line 44\n", + "#1 At class webfiori\\framework\scheduler\AbstractTask line 1097\n", + "#2 At class webfiori\\framework\scheduler\AbstractTask line 418\n", + "#3 At class webfiori\\framework\scheduler\AbstractTask line 951\n", + "#4 At class webfiori\\framework\scheduler\TasksManager line 673\n", + "#5 At class webfiori\\framework\scheduler\TasksManager line 139\n", + "#6 At class webfiori\\framework\cli\commands\SchedulerCommand line 86\n", + "#7 At class webfiori\\framework\cli\commands\SchedulerCommand line 328\n", + "#8 At class webfiori\\cli\CLICommand line 409\n", + "#9 At class webfiori\\cli\Runner line 684\n", + "#10 At class webfiori\\cli\Runner line 615\n", + "#11 At class webfiori\cli\Runner line 156\n", "Skip"]; $actual = $runner->getOutput(); $idx = 0; - + var_dump($actual); foreach ($expected as $item) { if ($item == 'Skip') { break; diff --git a/webfiori/framework/scheduler/AbstractTask.php b/webfiori/framework/scheduler/AbstractTask.php index d3d10887..210ea5cc 100644 --- a/webfiori/framework/scheduler/AbstractTask.php +++ b/webfiori/framework/scheduler/AbstractTask.php @@ -1525,8 +1525,14 @@ private function logExeException(Throwable $ex, string $meth = '') { TasksManager::log('Line: '.$ex->getLine()); TasksManager::log('Stack Trace:'); $index = 0; - - foreach ($ex->getTrace() as $traceEntry) { + $trace = debug_backtrace(); + $firstEntry = $ex->getTrace()[0]; + $firstEntry['line'] = $ex->getLine(); + $e = new TraceEntry($firstEntry); + TasksManager::log('#'.$index.' '.$e); + $index++; + + foreach ($trace as $traceEntry) { $e = new TraceEntry($traceEntry); TasksManager::log('#'.$index.' '.$e); $index++;