pomander
pomander copied to clipboard
$task_name can be undefined in Cli.php
In Cli.php TaskNotFoundException can be thrown by print_tasks method, so here variable $task_name will be undefined.
Unfortunately at this time no way to get missed task name here, but I've create PR to Phake in order to solve this.
Do you have an example of where this would occur? I stepped back through Phake to try to see where it might throw that exception, but I didn't notice anything.
$ bin/pom -T --trace
(in …)
#0 /vendor/jaz303/phake/lib/phake/Node.php(150): phake\Node->get_task('symfony:permiss...')
#1 /vendor/jaz303/phake/lib/phake/Node.php(110): phake\Node->get_task('symfony:permiss...')
#2 /vendor/jaz303/phake/lib/phake/Node.php(118): phake\Node->get_dependencies()
#3 /vendor/jaz303/phake/lib/phake/Node.php(154): phake\Node->has_dependencies()
#4 /vendor/jaz303/phake/lib/phake/Application.php(42): phake\Node->is_visible()
#5 /vendor/pomander/pomander/lib/Pomander/Cli.php(144): phake\Application->get_task_list()
#6 /vendor/pomander/pomander/lib/Pomander/Cli.php(49): Pomander\Cli->print_tasks()
#7 /vendor/pomander/pomander/bin/pom(23): Pomander\Cli->exec(Array)
#8 {main}
Interesting. So a node that has dependencies is unable to find its dependency. A quick workaround would be to insert a try/catch block into the print_tasks
function. The error message could be something like "Unable to get task list"
However calling get_task
on a dependency should work unless there is something else happening? A mis-named task perhaps?
Plugin task has nonexistent task in requirements.
I see. How do you feel about this?
protected function print_tasks()
{
try {
$task_list = $this->app->get_task_list();
if(!count($task_list)) return;
$max = max(array_map('strlen', array_keys($task_list)));
foreach($task_list as $name => $desc)
echo str_pad($name, $max + 4) . $desc . "\n";
} catch (Exception $e) {
$this->fatal($e, "Couldn't build the task list.");
}
}
I think that it'll OK for now. And I hope that my PR in some way will be accepted in Phake, so task name can be extracted from exception like this:
// exec
} catch (\phake\TaskNotFoundException $tnfe) {
$this->fatal($tnfe, "Task '{$tnfe->getTaskName()}' not found\n");
}
Great. Yeah, that would be nice if we could do that.
Changes made in Phake master, so $tnfe->getTaskName()
now available.
Even better. Thank you!
Maybe Phake can cut a release so this can get into Pomander?
About Phake release: https://twitter.com/jaz303/status/608573142886445057
Excellent. I'll keep an eye on the repo.