IcingaException: Add utility method to format exceptions as one-liner
This commit is contained in:
parent
c1a3d205bc
commit
982e226db0
|
@ -8,6 +8,7 @@ use Icinga\Data\ConfigObject;
|
|||
use Icinga\Application\Logger\Writer\FileWriter;
|
||||
use Icinga\Application\Logger\Writer\SyslogWriter;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
use Icinga\Exception\IcingaException;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
|
@ -226,13 +227,7 @@ class Logger
|
|||
$messages = array();
|
||||
$error = $message;
|
||||
do {
|
||||
$messages[] = sprintf(
|
||||
'%s in %s:%d with message: %s',
|
||||
get_class($error),
|
||||
$error->getFile(),
|
||||
$error->getLine(),
|
||||
$error->getMessage()
|
||||
);
|
||||
$messages[] = IcingaException::describe($error);
|
||||
} while ($error = $error->getPrevious());
|
||||
$message = implode(' <- ', $messages);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
namespace Icinga\Cli;
|
||||
|
||||
use Icinga\Application\ApplicationBootstrap as App;
|
||||
use Icinga\Exception\IcingaException;
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Cli\Params;
|
||||
use Icinga\Cli\Screen;
|
||||
|
@ -266,13 +267,7 @@ class Loader
|
|||
echo $this->formatTrace($e->getTrace());
|
||||
}
|
||||
|
||||
$this->fail(sprintf(
|
||||
'%s in %s:%d with message: %s',
|
||||
get_class($e),
|
||||
$e->getFile(),
|
||||
$e->getLine(),
|
||||
$e->getMessage()
|
||||
));
|
||||
$this->fail(IcingaException::describe($e));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,4 +25,24 @@ class IcingaException extends Exception
|
|||
}
|
||||
parent::__construct(vsprintf($message, $args), 0, $exc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the given exception formatted as one-liner
|
||||
*
|
||||
* The format used is: %class% in %path%:%line% with message: %message%
|
||||
*
|
||||
* @param Exception $exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function describe(Exception $exception)
|
||||
{
|
||||
return sprintf(
|
||||
'%s in %s:%d with message: %s',
|
||||
get_class($exception),
|
||||
$exception->getFile(),
|
||||
$exception->getLine(),
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue