Skip to content

Commit

Permalink
feature #14908 Include working directory in ProcessFailedException (R…
Browse files Browse the repository at this point in the history
…vanlaak)

This PR was merged into the 2.8 branch.

Discussion
----------

Include working directory in ProcessFailedException

... because quite often the Exception is a result of the `www-data` user not having the appropriate rights at that working path. Maybe @schmittjoh can confirm this?

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

dbaefb4 Include working directory in ProcessFailedException
  • Loading branch information
fabpot committed Oct 5, 2015
2 parents ef7aeaa + dbaefb4 commit 40cf393
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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",
$process->getCommandLine(),
$process->getExitCode(),
$process->getExitCodeText()
$process->getExitCodeText(),
$process->getWorkingDirectory()
);

if (!$process->isOutputDisabled()) {
Expand Down
18 changes: 14 additions & 4 deletions src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php
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,10 +82,14 @@ 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}",
$exception->getMessage()
);
}
Expand All @@ -98,10 +103,11 @@ 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

0 comments on commit 40cf393

Please sign in to comment.