1 | <?php |
||
24 | class PuliRunnerException extends RuntimeException |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $command; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $exitCode; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $shortError; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $fullError; |
||
45 | |||
46 | 3 | public static function forProcess(Process $process) |
|
47 | { |
||
48 | 3 | $shortError = $fullError = $process->getErrorOutput(); |
|
49 | |||
50 | 3 | if (preg_match('~^fatal: (.+)$~', $shortError, $matches)) { |
|
51 | 1 | $shortError = trim($matches[1]); |
|
52 | 2 | } elseif (preg_match('~^\s+\[([\w\\\\]+\\\\)?(\w+)\]\s+(.+)\r?\n\r?\n\S~s', $shortError, $matches)) { |
|
53 | 2 | $shortError = trim($matches[2]).': '.trim($matches[3]); |
|
54 | } |
||
55 | |||
56 | 3 | return new static($process->getCommandLine(), $process->getExitCode(), $shortError, $fullError); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param string $command |
||
61 | * @param int $exitCode |
||
62 | * @param string $shortError |
||
63 | * @param string $fullError |
||
64 | */ |
||
65 | 11 | public function __construct($command, $exitCode, $shortError, $fullError) |
|
66 | { |
||
67 | 11 | parent::__construct(sprintf( |
|
68 | 11 | 'An error occurred while running: %s (status %s): %s', |
|
69 | $command, |
||
70 | $exitCode, |
||
71 | $shortError |
||
72 | )); |
||
73 | |||
74 | 11 | $this->command = $command; |
|
75 | 11 | $this->exitCode = $exitCode; |
|
76 | 11 | $this->shortError = $shortError; |
|
77 | 11 | $this->fullError = $fullError; |
|
78 | 11 | } |
|
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 3 | public function getCommand() |
|
87 | |||
88 | /** |
||
89 | * @return int |
||
90 | */ |
||
91 | 3 | public function getExitCode() |
|
95 | |||
96 | /** |
||
97 | * @return string |
||
98 | */ |
||
99 | 11 | public function getShortError() |
|
103 | |||
104 | /** |
||
105 | * @return string |
||
106 | */ |
||
107 | 3 | public function getFullError() |
|
111 | } |
||
112 |