Skip to content

Commit

Permalink
Merge pull request #27 from WebFiori/dev
Browse files Browse the repository at this point in the history
feat: Show Stack Trace on Error
  • Loading branch information
usernane authored Aug 20, 2024
2 parents f5ab0bc + 69a514d commit a220e25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/webfiori/tests/cli/RunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ public function testRunner15() {
'exit'
]);
$runner->start();
$output = $runner->getOutput();
$output[12] = null;
$this->assertEquals([
">> Running in interactive mode.\n",
">> Type command name or 'exit' to close.\n",
Expand All @@ -392,9 +394,11 @@ public function testRunner15() {
"Code: 0\n",
"At: ".ROOT_DIR."tests".DS."webfiori".DS."tests".DS."cli".DS."testCommands".DS."WithExceptionCommand.php\n",
"Line: 12\n",
"Stack Trace: \n\n",
null,
"Command Exit Status: -1\n",
">> ",
], $runner->getOutput());
], $output);
}
/**
* @test
Expand Down Expand Up @@ -524,14 +528,19 @@ public function testRunner21() {
]);
$runner->setInputs([]);
$runner->start();
$output = $runner->getOutput();
//Removing the trace
$output[6] = null;
$this->assertEquals([
"Error: An exception was thrown.\n",
"Exception Message: Call to undefined method webfiori\\tests\cli\\testCommands\WithExceptionCommand::notExist()\n",
"Code: 0\n",
"At: ".ROOT_DIR."tests".DS."webfiori".DS."tests".DS."cli".DS."testCommands".DS."WithExceptionCommand.php\n",
"Line: 12\n",
"Stack Trace: \n\n",
null,
"Command Exit Status: -1\n"
], $runner->getOutput());
], $output);
}
/**
* @test
Expand Down
2 changes: 2 additions & 0 deletions webfiori/cli/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ public function runCommand(CLICommand $c = null, array $args = [], bool $ansi =
$this->printMsg($ex->getCode(), 'Code:', 'yellow');
$this->printMsg($ex->getFile(), 'At:', 'yellow');
$this->printMsg($ex->getLine(), 'Line:', 'yellow');
$this->printMsg("\n", 'Stack Trace:', 'yellow');
$this->printMsg("\n".$ex->getTraceAsString());
$this->commandExitVal = $ex->getCode() == 0 ? -1 : $ex->getCode();
}

Expand Down

0 comments on commit a220e25

Please sign in to comment.