pomander icon indicating copy to clipboard operation
pomander copied to clipboard

$task_name can be undefined in Cli.php

Open mekras opened this issue 10 years ago • 12 comments

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.

mekras avatar Oct 06 '14 08:10 mekras

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.

tamagokun avatar Oct 06 '14 11:10 tamagokun

$ 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}

mekras avatar Oct 06 '14 11:10 mekras

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?

tamagokun avatar Oct 06 '14 11:10 tamagokun

Plugin task has nonexistent task in requirements.

mekras avatar Oct 06 '14 11:10 mekras

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.");
    }
}

tamagokun avatar Oct 06 '14 11:10 tamagokun

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");
}

mekras avatar Oct 06 '14 11:10 mekras

Great. Yeah, that would be nice if we could do that.

tamagokun avatar Oct 06 '14 11:10 tamagokun

Changes made in Phake master, so $tnfe->getTaskName() now available.

mekras avatar Oct 07 '14 08:10 mekras

Even better. Thank you!

tamagokun avatar Oct 07 '14 10:10 tamagokun

Maybe Phake can cut a release so this can get into Pomander?

tamagokun avatar May 06 '15 13:05 tamagokun

About Phake release: https://twitter.com/jaz303/status/608573142886445057

mekras avatar Jun 10 '15 10:06 mekras

Excellent. I'll keep an eye on the repo.

tamagokun avatar Jun 10 '15 10:06 tamagokun