Skip to content

Include working directory in ProcessFailedException #14908

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

Merged
merged 1 commit into from
Oct 5, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public function __construct(Process $process)
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
}

$error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
$error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the double \n?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you paste an output example?

$process->getCommandLine(),
$process->getExitCode(),
$process->getExitCodeText()
$process->getExitCodeText(),
$process->getWorkingDirectory()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should skip it when it get null ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to improve error information if a process fails because of the lack of user rights on the working directory.

);

if (!$process->isOutputDisabled()) {
Expand Down
20 changes: 15 additions & 5 deletions src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
$exitText = 'General error';
$output = 'Command output';
$errorOutput = 'FATAL: Unexpected error';
$workingDirectory = getcwd();

$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled'),
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
array($cmd)
);
$process->expects($this->once())
Expand All @@ -81,27 +82,32 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
->method('isOutputDisabled')
->will($this->returnValue(false));

$process->expects($this->once())
->method('getWorkingDirectory')
->will($this->returnValue($workingDirectory));

$exception = new ProcessFailedException($process);

$this->assertEquals(
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a single line break between the exit code and the working directory would be enough IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the exception message also uses two line breaks, so while I was fixing the tests I've made it consistent by also adding them over here.

$exception->getMessage()
);
}

/**
* Tests that ProcessFailedException does not extract information from
* process output if it was previously disabled
* process output if it was previously disabled.
*/
public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
{
$cmd = 'php';
$exitCode = 1;
$exitText = 'General error';
$workingDirectory = getcwd();

$process = $this->getMock(
'Symfony\Component\Process\Process',
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput'),
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
array($cmd)
);
$process->expects($this->once())
Expand All @@ -126,10 +132,14 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
->method('isOutputDisabled')
->will($this->returnValue(true));

$process->expects($this->once())
->method('getWorkingDirectory')
->will($this->returnValue($workingDirectory));

$exception = new ProcessFailedException($process);

$this->assertEquals(
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)",
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
$exception->getMessage()
);
}
Expand Down