From 48fe4d12bf1fbdc7634ab3a4a3da96458cfb46e1 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 10:07:59 +0300 Subject: [PATCH 1/6] Added Support for Showing Stack Trace for Tasks --- webfiori/framework/scheduler/AbstractTask.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webfiori/framework/scheduler/AbstractTask.php b/webfiori/framework/scheduler/AbstractTask.php index e9ab0cb98..9d81ed8c8 100644 --- a/webfiori/framework/scheduler/AbstractTask.php +++ b/webfiori/framework/scheduler/AbstractTask.php @@ -1504,8 +1504,9 @@ private function logExeException(Throwable $ex, string $meth = '') { TasksManager::log('Exception message: '.$ex->getMessage()); TasksManager::log('Thrown in: '.Util::extractClassName($ex->getFile())); TasksManager::log('Line: '.$ex->getLine()); - - + TasksManager::log("Stack Trace:"); + TasksManager::log($ex->getTraceAsString()); + if ($meth == 'execute') { $this->isSuccess = false; } From 3d52a2f14f6af2813bb15d3d96da038069f32b14 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 10:28:10 +0300 Subject: [PATCH 2/6] Update AbstractTask.php --- webfiori/framework/scheduler/AbstractTask.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/webfiori/framework/scheduler/AbstractTask.php b/webfiori/framework/scheduler/AbstractTask.php index 9d81ed8c8..acbf478fb 100644 --- a/webfiori/framework/scheduler/AbstractTask.php +++ b/webfiori/framework/scheduler/AbstractTask.php @@ -13,6 +13,7 @@ use Exception; use Throwable; use webfiori\collections\Queue; +use webfiori\error\TraceEntry; use webfiori\framework\cli\commands\SchedulerCommand; use webfiori\framework\exceptions\InvalidCRONExprException; use webfiori\framework\Util; @@ -1504,9 +1505,15 @@ private function logExeException(Throwable $ex, string $meth = '') { TasksManager::log('Exception message: '.$ex->getMessage()); TasksManager::log('Thrown in: '.Util::extractClassName($ex->getFile())); TasksManager::log('Line: '.$ex->getLine()); - TasksManager::log("Stack Trace:"); - TasksManager::log($ex->getTraceAsString()); - + TasksManager::log('Stack Trace:'); + $index = 0; + + foreach ($ex->getTrace() as $traceEntry) { + $e = new TraceEntry($traceEntry); + TasksManager::log('#'.$index.' '.$e); + $index++; + } + if ($meth == 'execute') { $this->isSuccess = false; } From 7f699212e42506b13210421a5dd5f00d0ed71aba Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 12:43:01 +0300 Subject: [PATCH 3/6] Update SchedulerCommandTest.php --- .../test/cli/SchedulerCommandTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php index 2a533f9a6..033548360 100644 --- a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php +++ b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php @@ -169,6 +169,28 @@ public function test05() { "Exception message: Call to undefined method app\\tasks\Fail2TestTask::undefined()\n", "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 904\n", + "#3 At class webfiori\\framework\scheduler\TasksManager line 600\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", + "#11 At class webfiori\\framework\\test\cli\SchedulerCommandTest line 1267\n", + "#12 At class PHPUnit\Framework\TestCase line 933\n", + "#13 At class PHPUnit\Framework\TestCase line 588\n", + "#14 At class PHPUnit\Framework\TestResult line 724\n", + "#15 At class PHPUnit\Framework\TestCase line 505\n", + "#16 At class PHPUnit\Framework\TestSuite line 505\n", + "#17 At class PHPUnit\Framework\TestSuite line 484\n", + "#18 At class PHPUnit\TextUI\TestRunner line 125\n", + "#19 At class PHPUnit\TextUI\Command line 94\n", + "#20 At class PHPUnit\TextUI\Command line 2303\n", "Calling the method app\\tasks\Fail2TestTask::onFail()\n", "Calling the method app\\tasks\Fail2TestTask::afterExec()\n", "Check finished.\n", From 523b95000828aa8ff1813f782f2b9bd737dac64c Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 12:50:01 +0300 Subject: [PATCH 4/6] Update SchedulerCommandTest.php --- .../test/cli/SchedulerCommandTest.php | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php index 033548360..8c99903f4 100644 --- a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php +++ b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php @@ -152,7 +152,7 @@ public function test05() { 'p' => '123456' ]); $this->assertEquals(0, $runner->start()); - $this->assertEquals([ + $expected = [ "Select one of the scheduled tasks to force:\n", "0: Fail 1\n", "1: Fail 2\n", @@ -182,25 +182,16 @@ public function test05() { "#9 At class webfiori\\cli\Runner line 615\n", "#10 At class webfiori\cli\Runner line 154\n", "#11 At class webfiori\\framework\\test\cli\SchedulerCommandTest line 1267\n", - "#12 At class PHPUnit\Framework\TestCase line 933\n", - "#13 At class PHPUnit\Framework\TestCase line 588\n", - "#14 At class PHPUnit\Framework\TestResult line 724\n", - "#15 At class PHPUnit\Framework\TestCase line 505\n", - "#16 At class PHPUnit\Framework\TestSuite line 505\n", - "#17 At class PHPUnit\Framework\TestSuite line 484\n", - "#18 At class PHPUnit\TextUI\TestRunner line 125\n", - "#19 At class PHPUnit\TextUI\Command line 94\n", - "#20 At class PHPUnit\TextUI\Command line 2303\n", - "Calling the method app\\tasks\Fail2TestTask::onFail()\n", - "Calling the method app\\tasks\Fail2TestTask::afterExec()\n", - "Check finished.\n", - "Total number of tasks: 5\n", - "Executed Tasks: 1\n", - "Successfully finished tasks:\n", - " \n", - "Failed tasks:\n", - " Fail 2\n" - ], $runner->getOutput()); + "Skip"]; + $actual = $runner->getOutput(); + $idx = 0; + foreach ($expected as $item) { + if ($item == 'Skip') { + break; + } + $this->assertEquals($item, $actual[$idx]); + $idx++; + } } /** * @test From f12d58760ff8b630c19d8e745ce6f0a3df9282b7 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 12:53:08 +0300 Subject: [PATCH 5/6] Update SchedulerCommandTest.php --- tests/webfiori/framework/test/cli/SchedulerCommandTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php index 8c99903f4..a0b436d16 100644 --- a/tests/webfiori/framework/test/cli/SchedulerCommandTest.php +++ b/tests/webfiori/framework/test/cli/SchedulerCommandTest.php @@ -181,7 +181,6 @@ public function test05() { "#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", - "#11 At class webfiori\\framework\\test\cli\SchedulerCommandTest line 1267\n", "Skip"]; $actual = $runner->getOutput(); $idx = 0; From 18f9546804a1a81ba52557e7ddad236abcaf8ab9 Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 17 Oct 2023 12:57:29 +0300 Subject: [PATCH 6/6] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 96c541ff0..00e51b9ad 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "webfiori/jsonx":"v3.3.0", "webfiori/ui":"v2.5.6", "webfiori/collections":"v1.1.3", - "webfiori/database":"v0.8.3", + "webfiori/database":"v0.8.4", "webfiori/cli":"v1.1.3", "webfiori/mailer":"v1.1.1", "webfiori/err":"v1.0.6"