File tree 7 files changed +83
-26
lines changed
src/Symfony/Component/Process
7 files changed +83
-26
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ CHANGELOG
6
6
7
7
* added the ` Process::isTtySupported() ` method that allows to check for TTY support
8
8
* 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
9
10
10
11
4.0.0
11
12
-----
Original file line number Diff line number Diff line change 18
18
*
19
19
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
20
20
*/
21
- class ProcessFailedException extends RuntimeException
21
+ class ProcessFailedException extends ProcessRuntimeException
22
22
{
23
- private $ process ;
24
-
25
23
public function __construct (Process $ process )
26
24
{
27
25
if ($ process ->isSuccessful ()) {
@@ -42,13 +40,6 @@ public function __construct(Process $process)
42
40
);
43
41
}
44
42
45
- parent ::__construct ($ error );
46
-
47
- $ this ->process = $ process ;
48
- }
49
-
50
- public function getProcess ()
51
- {
52
- return $ this ->process ;
43
+ parent ::__construct ($ process , $ error );
53
44
}
54
45
}
Original file line number Diff line number Diff line change
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
+ * @author Sullivan Senechal <soullivaneuh@gmail.com>
18
+ */
19
+ class ProcessRuntimeException extends RuntimeException
20
+ {
21
+ private $ process ;
22
+
23
+ public function __construct (Process $ process , string $ message = '' )
24
+ {
25
+ parent ::__construct ($ message );
26
+
27
+ $ this ->process = $ process ;
28
+ }
29
+
30
+ public function getProcess (): Process
31
+ {
32
+ return $ this ->process ;
33
+ }
34
+ }
Original file line number Diff line number Diff line change
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 ProcessRuntimeException
22
+ {
23
+ public function __construct (Process $ process )
24
+ {
25
+ parent ::__construct ($ process , sprintf (
26
+ 'The process has been signaled with signal "%s". ' ,
27
+ $ process ->getTermSignal ()
28
+ ));
29
+ }
30
+
31
+ public function getSignal (): int
32
+ {
33
+ return $ this ->getProcess ()->getTermSignal ();
34
+ }
35
+ }
Original file line number Diff line number Diff line change 18
18
*
19
19
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
20
20
*/
21
- class ProcessTimedOutException extends RuntimeException
21
+ class ProcessTimedOutException extends ProcessRuntimeException
22
22
{
23
23
const TYPE_GENERAL = 1 ;
24
24
const TYPE_IDLE = 2 ;
25
25
26
- private $ process ;
27
26
private $ timeoutType ;
28
27
29
28
public function __construct (Process $ process , int $ timeoutType )
30
29
{
31
- $ this ->process = $ process ;
32
30
$ this ->timeoutType = $ timeoutType ;
33
31
34
- parent ::__construct (sprintf (
32
+ parent ::__construct ($ process );
33
+
34
+ $ this ->message = sprintf (
35
35
'The process "%s" exceeded the timeout of %s seconds. ' ,
36
36
$ process ->getCommandLine (),
37
37
$ this ->getExceededTimeout ()
38
- ));
39
- }
40
-
41
- public function getProcess ()
42
- {
43
- return $ this ->process ;
38
+ );
44
39
}
45
40
46
41
public function isGeneralTimeout ()
@@ -57,10 +52,10 @@ public function getExceededTimeout()
57
52
{
58
53
switch ($ this ->timeoutType ) {
59
54
case self ::TYPE_GENERAL :
60
- return $ this ->process ->getTimeout ();
55
+ return $ this ->getProcess () ->getTimeout ();
61
56
62
57
case self ::TYPE_IDLE :
63
- return $ this ->process ->getIdleTimeout ();
58
+ return $ this ->getProcess () ->getIdleTimeout ();
64
59
65
60
default :
66
61
throw new \LogicException (sprintf ('Unknown timeout type "%d". ' , $ this ->timeoutType ));
Original file line number Diff line number Diff line change 14
14
use Symfony \Component \Process \Exception \InvalidArgumentException ;
15
15
use Symfony \Component \Process \Exception \LogicException ;
16
16
use Symfony \Component \Process \Exception \ProcessFailedException ;
17
+ use Symfony \Component \Process \Exception \ProcessSignaledException ;
17
18
use Symfony \Component \Process \Exception \ProcessTimedOutException ;
18
19
use Symfony \Component \Process \Exception \RuntimeException ;
19
20
use Symfony \Component \Process \Pipes \PipesInterface ;
@@ -387,7 +388,7 @@ public function wait(callable $callback = null)
387
388
}
388
389
389
390
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 );
391
392
}
392
393
393
394
return $ this ->exitcode ;
Original file line number Diff line number Diff line change @@ -688,8 +688,8 @@ public function testProcessIsSignaledIfStopped()
688
688
}
689
689
690
690
/**
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".
693
693
*/
694
694
public function testProcessThrowsExceptionWhenExternallySignaled ()
695
695
{
You can’t perform that action at this time.
0 commit comments