Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

$task_name can be undefined in Cli.php #62

Open
mekras opened this issue Oct 6, 2014 · 12 comments
Open

$task_name can be undefined in Cli.php #62

mekras opened this issue Oct 6, 2014 · 12 comments

Comments

@mekras
Copy link
Contributor

mekras commented Oct 6, 2014

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.

@tamagokun
Copy link
Owner

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.

@mekras
Copy link
Contributor Author

mekras commented Oct 6, 2014

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

@tamagokun
Copy link
Owner

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?

@mekras
Copy link
Contributor Author

mekras commented Oct 6, 2014

Plugin task has nonexistent task in requirements.

@tamagokun
Copy link
Owner

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

@mekras
Copy link
Contributor Author

mekras commented Oct 6, 2014

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

@tamagokun
Copy link
Owner

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

@mekras
Copy link
Contributor Author

mekras commented Oct 7, 2014

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

@tamagokun
Copy link
Owner

Even better. Thank you!

@tamagokun
Copy link
Owner

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

@mekras
Copy link
Contributor Author

mekras commented Jun 10, 2015

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

@tamagokun
Copy link
Owner

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants