[Intl] Added exception handler to command line scripts
This commit is contained in:
parent
2349839738
commit
9052efc499
|
@ -11,11 +11,11 @@
|
|||
|
||||
define('LINE_WIDTH', 75);
|
||||
|
||||
define('LINE', str_repeat('-', LINE_WIDTH) . "\n");
|
||||
define('LINE', str_repeat('-', LINE_WIDTH)."\n");
|
||||
|
||||
function bailout($message)
|
||||
{
|
||||
echo wordwrap($message, LINE_WIDTH) . " Aborting.\n";
|
||||
echo wordwrap($message, LINE_WIDTH)." Aborting.\n";
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ function centered($text)
|
|||
{
|
||||
$padding = (int) ((LINE_WIDTH - strlen($text))/2);
|
||||
|
||||
return str_repeat(' ', $padding) . $text;
|
||||
return str_repeat(' ', $padding).$text;
|
||||
}
|
||||
|
||||
function cd($dir)
|
||||
|
@ -47,7 +47,7 @@ function run($command)
|
|||
|
||||
if (0 !== $status) {
|
||||
$output = implode("\n", $output);
|
||||
echo "Error while running:\n " . getcwd() . '$ ' . $command . "\nOutput:\n" . LINE . "$output\n" . LINE;
|
||||
echo "Error while running:\n ".getcwd().'$ '.$command."\nOutput:\n".LINE."$output\n".LINE;
|
||||
|
||||
bailout("\"$command\" failed.");
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ function run($command)
|
|||
|
||||
function get_icu_version_from_genrb($genrb)
|
||||
{
|
||||
exec($genrb . ' --version 2>&1', $output, $status);
|
||||
exec($genrb.' --version 2>&1', $output, $status);
|
||||
|
||||
if (0 !== $status) {
|
||||
bailout($genrb . ' failed.');
|
||||
bailout($genrb.' failed.');
|
||||
}
|
||||
|
||||
if (!preg_match('/ICU version ([\d\.]+)/', implode('', $output), $matches)) {
|
||||
|
@ -67,3 +67,27 @@ function get_icu_version_from_genrb($genrb)
|
|||
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
set_exception_handler(function (\Exception $exception) {
|
||||
echo "\n";
|
||||
|
||||
$cause = $exception;
|
||||
$root = true;
|
||||
|
||||
while (null !== $cause) {
|
||||
if (!$root) {
|
||||
echo "Caused by\n";
|
||||
}
|
||||
|
||||
echo get_class($cause).": ".$cause->getMessage()."\n";
|
||||
echo "\n";
|
||||
echo $cause->getFile().":".$cause->getLine()."\n";
|
||||
foreach ($cause->getTrace() as $trace) {
|
||||
echo $trace['file'].":".$trace['line']."\n";
|
||||
}
|
||||
echo "\n";
|
||||
|
||||
$cause = $cause->getPrevious();
|
||||
$root = false;
|
||||
}
|
||||
});
|
||||
|
|
Reference in New Issue