summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-04-26 11:26:58 +0200
committerAleksander Machniak <alec@alec.pl>2013-04-26 11:28:50 +0200
commitae0c133d45fbb95a8266db505033690af46b4363 (patch)
tree99978517f02452e40fee492a372897902d54e0a9 /program/lib/Roundcube/rcube.php
parent23ea51e98df7f1591ff0b788809b4eba784ab27d (diff)
Fix error handling in CLI mode, use STDERR and non-empty exit code (#1489043)
Conflicts: program/lib/Roundcube/rcube.php
Diffstat (limited to 'program/lib/Roundcube/rcube.php')
-rw-r--r--program/lib/Roundcube/rcube.php30
1 files changed, 23 insertions, 7 deletions
diff --git a/program/lib/Roundcube/rcube.php b/program/lib/Roundcube/rcube.php
index b2595668e..b681f0531 100644
--- a/program/lib/Roundcube/rcube.php
+++ b/program/lib/Roundcube/rcube.php
@@ -1074,14 +1074,20 @@ class rcube
{
// handle PHP exceptions
if (is_object($arg) && is_a($arg, 'Exception')) {
- $err = array(
+ $arg = array(
'type' => 'php',
'code' => $arg->getCode(),
'line' => $arg->getLine(),
'file' => $arg->getFile(),
'message' => $arg->getMessage(),
);
- $arg = $err;
+ }
+ else if (is_string($arg)) {
+ $arg = array('message' => $arg, 'type' => 'php');
+ }
+
+ if (empty($arg['code'])) {
+ $arg['code'] = 500;
}
// installer
@@ -1091,14 +1097,24 @@ class rcube
return;
}
- if (($log || $terminate) && $arg['type'] && $arg['message']) {
+ $cli = php_sapi_name() == 'cli';
+
+ if (($log || $terminate) && !$cli && $arg['type'] && $arg['message']) {
$arg['fatal'] = $terminate;
self::log_bug($arg);
}
- // display error page and terminate script
- if ($terminate && is_object(self::$instance->output)) {
- self::$instance->output->raise_error($arg['code'], $arg['message']);
+ // terminate script
+ if ($terminate) {
+ // display error page
+ if (is_object(self::$instance->output)) {
+ self::$instance->output->raise_error($arg['code'], $arg['message']);
+ }
+ else if ($cli) {
+ fwrite(STDERR, 'ERROR: ' . $arg['message']);
+ }
+
+ exit(1);
}
}
@@ -1137,7 +1153,7 @@ class rcube
if (!self::write_log('errors', $log_entry)) {
// send error to PHPs error handler if write_log didn't succeed
- trigger_error($arg_arr['message']);
+ trigger_error($arg_arr['message'], E_USER_WARNING);
}
}