10000 Introduce signaled process specific exception class · symfony/symfony@68adb3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 68adb3b

Browse files
committed
Introduce signaled process specific exception class
1 parent 1df45e4 commit 68adb3b

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

src/Symfony/Component/Process/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

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

1011
4.0.0
1112
-----
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Process\Exception;
13+
14+
use Symfony\Component\Process\Process;
15+
16+
/**
17+
* Exception that is thrown when a process has been signaled.
18+
*
19+
* @author Sullivan Senechal <soullivaneuh@gmail.com>
20+
*/
21+
final class ProcessSignaledException extends RuntimeException
22+
{
23+
private $process;
24+
25+
public function __construct(Process $process)
26+
{
27+
$this->process = $process;
28+
29+
parent::__construct(sprintf('The process has been signaled with signal "%s".', $process->getTermSignal()));
30+
}
31+
32+
public function getProcess(): Process
33+
{
34+
return $this->process;
35+
}
36+
37+
public function getSignal(): int
38+
{
39+
return $this->getProcess()->getTermSignal();
40+
}
41+
}

src/Symfony/Component/Process/Process.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Process\Exception\InvalidArgumentException;
1515
use Symfony\Component\Process\Exception\LogicException;
1616
use Symfony\Component\Process\Exception\ProcessFailedException;
17+
use Symfony\Component\Process\Exception\ProcessSignaledException;
1718
use Symfony\Component\Process\Exception\ProcessTimedOutException;
1819
use Symfony\Component\Process\Exception\RuntimeException;
1920
use Symfony\Component\Process\Pipes\PipesInterface;
@@ -387,7 +388,7 @@ public function wait(callable $callback = null)
387388
}
388389

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

393394
return $this->exitcode;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ public function testProcessIsSignaledIfStopped()
688688
}
689689

690690
/**
691-
* @expectedException \Symfony\Component\Process\Exception\RuntimeException
692-
* @expectedExceptionMessage The process has been signaled
691+
* @expectedException \Symfony\Component\Process\Exception\ProcessSignaledException
692+
* @expectedExceptionMessage The process has been signaled with signal "9".
693693
*/
694694
public function testProcessThrowsExceptionWhenExternallySignaled()
695695
{

0 commit comments

Comments
 (0)
0