-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Process] fixed fatal errors in getOutput and getErrorOutput when process was not started #9452
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
Conversation
* @return string The process output | ||
* | ||
* @api | ||
*/ | ||
public function getOutput() | ||
{ | ||
if (!$this->isStarted()) { | ||
throw new LogicException(sprintf('%s does not make sense if command is not started', __FUNCTION__)); |
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.
Process must be started before calling __FUNCTION__
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.
+1
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.
Edited Command -> Process
@Tobion thanks, code will be fixed |
@@ -401,12 +406,17 @@ public function getIncrementalOutput() | |||
/** | |||
* Returns the current error output of the process (STDERR). | |||
* | |||
* @throws Exception\LogicException |
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.
As @Tobion said - throws after return with empty line between. You can find an example in here http://symfony.com/doc/current/contributing/code/standards.html
@Tobion, @piotrpasich, thanks! |
Looking at the process code, it looks to me that there will also be PHP errors when calling some other methods before starting the process. For example |
OK, I will look at them on weekend. |
I have noticed that many similar problems are beginning in if (self::STATUS_STARTED !== $this->status) {
return;
} Maybe it would be better to throw logic exception instead of simple Thus we can don't throw logic exceptions in all dependent methods. @Tobion, what you think about it? |
Another opinions will come in handy :) |
@@ -371,10 +371,16 @@ public function signal($signal) | |||
* | |||
* @return string The process output | |||
* | |||
* @throws Exception\LogicException In case the process is not started |
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.
Exception\LogicException does not correspond with the class used in the code (LogicException
) on of those should be changed (same below)
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.
ping @max-voloshin
@max-voloshin do you have plans to finish this PR? |
@jakzal , finish:) Similar problems can be fixed in another PR, if anyone has enough experience for this. |
@romainneutron Can you check this PR please? |
This looks good to me. @max-voloshin FYI the |
Humm, wait. The check on I'm doing some tests right now |
this piece of code should fail (and actually does not) : $process = new Process('php -m');
$process->run();
$process->wait(); |
@romainneutron , thanks! I will add tests for this and improve code. |
*/ | ||
public function wait($callback = null) | ||
{ | ||
if (!$this->isStarted()) { |
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.
this should be if (!$this->isStarted() || $this->status === self::STATUS_TERMINATED)
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.
@romainneutron, with this change I break testTTYCommand
, because in start
method we have
if ($this->tty) {
$this->status = self::STATUS_TERMINATED;
return;
}
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.
:(
I've to admit the TTY mode is something I don't know very well. I'm gonna dig this tonight
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.
Hello and sorry for the late reply,
I've justed submitted #10412 that should make this change doable and your PR mergeable
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.
@romainneutron, thanks! I will wait for merging your PR and then rebase my branch with 2.3
#10412 has been merged now. |
My remark #9452 (comment) at is still open and I think we should not merge this before finding a general solution. @max-voloshin I basically agree with #9452 (comment) but it doesnt work universally. In |
Hello @Tobion, thanks for your comment. The following code: error_reporting(-1);
ini_set('display_errors', 'on');
$a = null;
var_dump($a['key']); produces :
whereas (note that error_reporting(-1);
ini_set('display_errors', 'on');
$a = array();
var_dump($a['key']); produces :
So the following code should not produce any error: $process = new Process('php -m');
$process->getTermSignal(); |
I've done a review of the methods and here's what could be fixed:
What about other methods that point to the final status of the process such as
public function checkTimeout()
{
if ($this->status !== self::STATUS_STARTED) {
return;
}
// ...
} |
@romainneutron Thanks for the information. I didn't know that. One can learn php inconsistencies even after many years.. But even when it does not throw an error, the methods will not return the expected values. So |
right, do you think we should cast to a boolean or throw an exception in case the process has not run ? |
Agreed |
Closing in favor of #10480 |
…ut when process was not started (romainneutron) This PR was merged into the 2.3 branch. Discussion ---------- [Process] Fixed fatal errors in getOutput and getErrorOutput when process was not started | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10022 | License | MIT This PR replaces #9452 and address the latest changes. Side note : I've not updated `getExitCode`, `getExitCodeText` and `isSuccessful` as they were explicitly tested to return null in case the process is not started or terminated. I think it would be a BC break to do that. Commits ------- 449fe01 [Process] Trow exceptions in case a Process method is supposed to be called after termination 0ae6858 [Process] fixed fatal errors in getOutput and getErrorOutput when process was not started
Added logic exceptions for prevent fatal errors in
getOutput
andgetErrorOutput
when process was not started.