Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improved error/exception reporting in Task::perform() #831

Merged
merged 1 commit into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions classes/phing/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,35 @@ public function maybeConfigure()
/**
* Perfrom this task
*
* @return void
*
* @throws BuildException
* @throws Error
*/
public function perform()
public function perform(): void
{
$reason = null;
try { // try executing task
$this->project->fireTaskStarted($this);
$this->maybeConfigure();
DispatchUtils::main($this);
$this->project->fireTaskFinished($this, $null = null);
} catch (Exception $exc) {
if ($exc instanceof BuildException) {
if ($this->getLocation() !== null) {
$exc->setLocation($this->getLocation());
}
} catch (\BuildException $ex) {
$loc = $ex->getLocation();
if ($loc === null || (string) $loc === '') {
$ex->setLocation($this->getLocation());
}
$this->project->fireTaskFinished($this, $exc);
throw $exc;
$reason = $ex;
throw $ex;
} catch (\Exception $ex) {
$reason = $ex;
$be = new \BuildException($ex);
$be->setLocation($this->getLocation());
throw $be;
} catch (\Error $ex) {
$reason = $ex;
throw $ex;
} finally {
$this->project->fireTaskFinished($this, $reason);
}
}
}
8 changes: 6 additions & 2 deletions test/classes/phing/tasks/TaskdefTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public function testNoClassname()
}

/**
* @expectedException \PHPUnit\Framework\Error\Error
* @expectedException BuildException
*/
public function testClassNotFound()
{
try {
$this->expectBuildException("classNotFound", "classname specified doesn't exist");
$this->executeTarget("classNotFound");
$this->fail(
"Should throw ConfigurationException because: " .
"classname specified doesn't exist"
);
} catch (ConfigurationException $e) {
//ignored
}
Expand Down
2 changes: 1 addition & 1 deletion test/classes/phing/tasks/TypedefTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testNoClassname()
}

/**
* @expectedException \PHPUnit\Framework\Error\Error
* @expectedException BuildException
*/
public function testClassNotFound()
{
Expand Down