Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40cf393

Browse files
committed
feature #14908 Include working directory in ProcessFailedException (Rvanlaak)
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
2 parents ef7aeaa + dbaefb4 commit 40cf393

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Symfony/Component/Process/Exception/ProcessFailedException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ public function __construct(Process $process)
2828
throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
2929
}
3030

31-
$error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
31+
$error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
3232
$process->getCommandLine(),
3333
$process->getExitCode(),
34-
$process->getExitCodeText()
34+
$process->getExitCodeText(),
35+
$process->getWorkingDirectory()
3536
);
3637

3738
if (!$process->isOutputDisabled()) {

src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
5151
$exitText = 'General error';
5252
$output = 'Command output';
5353
$errorOutput = 'FATAL: Unexpected error';
54+
$workingDirectory = getcwd();
5455

5556
$process = $this->getMock(
5657
'Symfony\Component\Process\Process',
57-
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled'),
58+
array('isSuccessful', 'getOutput', 'getErrorOutput', 'getExitCode', 'getExitCodeText', 'isOutputDisabled', 'getWorkingDirectory'),
5859
array($cmd)
5960
);
6061
$process->expects($this->once())
@@ -81,10 +82,14 @@ public function testProcessFailedExceptionPopulatesInformationFromProcessOutput(
8182
->method('isOutputDisabled')
8283
->will($this->returnValue(false));
8384

85+
$process->expects($this->once())
86+
->method('getWorkingDirectory')
87+
->will($this->returnValue($workingDirectory));
88+
8489
$exception = new ProcessFailedException($process);
8590

8691
$this->assertEquals(
87-
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
92+
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}\n\nOutput:\n================\n{$output}\n\nError Output:\n================\n{$errorOutput}",
8893
$exception->getMessage()
8994
);
9095
}
@@ -98,10 +103,11 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
98103
$cmd = 'php';
99104
$exitCode = 1;
100105
$exitText = 'General error';
106+
$workingDirectory = getcwd();
101107

102108
$process = $this->getMock(
103109
'Symfony\Component\Process\Process',
104-
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput'),
110+
array('isSuccessful', 'isOutputDisabled', 'getExitCode', 'getExitCodeText', 'getOutput', 'getErrorOutput', 'getWorkingDirectory'),
105111
array($cmd)
106112
);
107113
$process->expects($this->once())
@@ -126,10 +132,14 @@ public function testDisabledOutputInFailedExceptionDoesNotPopulateOutput()
126132
->method('isOutputDisabled')
127133
->will($this->returnValue(true));
128134

135+
$process->expects($this->once())
136+
->method('getWorkingDirectory')
137+
->will($this->returnValue($workingDirectory));
138+
129139
$exception = new ProcessFailedException($process);
130140

131141
$this->assertEquals(
132-
"The command \"$cmd\" failed.\nExit Code: $exitCode($exitText)",
142+
"The command \"$cmd\" failed.\n\nExit Code: $exitCode($exitText)\n\nWorking directory: {$workingDirectory}",
133143
$exception->getMessage()
134144
);
135145
}

0 commit comments

Comments
 (0)