Skip to content

Commit

Permalink
feature #25775 Introduce signaled process specific exception class (S…
Browse files Browse the repository at this point in the history
…oullivaneuh)

This PR was merged into the 4.1-dev branch.

Discussion
----------

Introduce signaled process specific exception class

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25768
| License       | MIT
| Doc PR        | N/A

Introduced the `ProcessSignaledException` class to properly catch signaled process errors.

I took benefit to refactor process exception with a new `ProcessRuntimeException` class.

Commits
-------

68adb3b Introduce signaled process specific exception class
  • Loading branch information
fabpot committed Jan 23, 2018
2 parents 8cf8d16 + 68adb3b commit 1850ffc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Process/CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* added the `Process::isTtySupported()` method that allows to check for TTY support
* made `PhpExecutableFinder` look for the `PHP_BINARY` env var when searching the php binary
* added the `ProcessSignaledException` class to properly catch signaled process errors

4.0.0
-----
Expand Down
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Process\Exception;

use Symfony\Component\Process\Process;

/**
* Exception that is thrown when a process has been signaled.
*
* @author Sullivan Senechal <soullivaneuh@gmail.com>
*/
final class ProcessSignaledException extends RuntimeException
{
private $process;

public function __construct(Process $process)
{
$this->process = $process;

parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
}

public function getProcess(): Process
{
return $this->process;
}

public function getSignal(): int
{
return $this->getProcess()->getTermSignal();
}
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/Process/Process.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessSignaledException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Pipes\PipesInterface;
Expand Down Expand Up @@ -389,7 +390,7 @@ public function wait(callable $callback = null)
}

if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
throw new ProcessSignaledException($this);
}

return $this->exitcode;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -688,8 +688,8 @@ public function testProcessIsSignaledIfStopped()
}

/**
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
* @expectedExceptionMessage The process has been signaled
* @expectedException \Symfony\Component\Process\Exception\ProcessSignaledException
* @expectedExceptionMessage The process has been signaled with signal "9".
*/
public function testProcessThrowsExceptionWhenExternallySignaled()
{
Expand Down

0 comments on commit 1850ffc

Please sign in to comment.