-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should skip it when it get There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
|
@@ -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}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
|
@@ -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() | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the double \n?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see https://github.com/symfony/symfony/pull/14908/files#r31994705
There was a problem hiding this comment.
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?