4
* Exception thrown when a system command fails.
6
final class CommandException extends Exception {
13
public function __construct($message, $command, $error, $stdout, $stderr) {
14
$this->command = $command;
15
$this->error = $error;
16
$this->stdout = $stdout;
17
$this->stderr = $stderr;
20
$summary[] = $this->summarize($message);
22
$summary[] = 'COMMAND';
23
$summary[] = $this->summarize($command);
26
$summary[] = 'STDOUT';
27
$summary[] = $this->summarize($stdout);
30
$summary[] = 'STDERR';
31
$summary[] = $this->summarize($stderr);
33
$summary = implode("\n", $summary);
35
parent::__construct($summary);
38
public function getCommand() {
39
return $this->command;
42
public function getError() {
46
public function getStdout() {
50
public function getStderr() {
54
private function summarize($string) {
55
if (!strlen($string)) {
61
$len = strlen($string);
64
$suffix = '... ('.number_format($cut).' more bytes) ...';
65
if ($cut > strlen($suffix)) {
66
$string = substr($string, 0, $limit).$suffix;
70
// Strip out any credentials for the purpose of building a human readable
71
// summary of the exception, since these are rarely-if-ever useful when
72
// debugging, but can expose otherwise sensitive information.
73
$string = phutil_censor_credentials($string);