Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F100510974
CommandException.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 31, 08:57
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Feb 2, 08:57 (2 d)
Engine
blob
Format
Raw Data
Handle
23973368
Attached To
rPHU libphutil
CommandException.php
View Options
<?php
/**
* Exception thrown when a system command fails.
*/
final
class
CommandException
extends
Exception
{
protected
$command
;
protected
$stdout
;
protected
$stderr
;
protected
$error
;
public
function
__construct
(
$message
,
$command
,
$error
,
$stdout
,
$stderr
)
{
$this
->
command
=
$command
;
$this
->
error
=
$error
;
$this
->
stdout
=
$stdout
;
$this
->
stderr
=
$stderr
;
$summary
=
array
();
$summary
[]
=
$this
->
summarize
(
$message
);
$summary
[]
=
'COMMAND'
;
$summary
[]
=
$this
->
summarize
(
$command
);
$summary
[]
=
null
;
$summary
[]
=
'STDOUT'
;
$summary
[]
=
$this
->
summarize
(
$stdout
);
$summary
[]
=
null
;
$summary
[]
=
'STDERR'
;
$summary
[]
=
$this
->
summarize
(
$stderr
);
$summary
=
implode
(
"
\n
"
,
$summary
);
parent
::
__construct
(
$summary
);
}
public
function
getCommand
()
{
return
$this
->
command
;
}
public
function
getError
()
{
return
$this
->
error
;
}
public
function
getStdout
()
{
return
$this
->
stdout
;
}
public
function
getStderr
()
{
return
$this
->
stderr
;
}
private
function
summarize
(
$string
)
{
if
(!
strlen
(
$string
))
{
return
'(empty)'
;
}
$limit
=
1000
;
$len
=
strlen
(
$string
);
if
(
$len
>
$limit
)
{
$cut
=
$len
-
$limit
;
$suffix
=
pht
(
'... (%d more bytes) ...'
,
number_format
(
$cut
));
if
(
$cut
>
strlen
(
$suffix
))
{
$string
=
substr
(
$string
,
0
,
$limit
).
$suffix
;
}
}
// Strip out any credentials for the purpose of building a human readable
// summary of the exception, since these are rarely-if-ever useful when
// debugging, but can expose otherwise sensitive information.
$string
=
phutil_censor_credentials
(
$string
);
return
$string
;
}
}
Event Timeline
Log In to Comment