Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1051581
D177.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jul 4, 1:50 AM
Size
3 KB
Mime Type
text/x-diff
Expires
Sat, Jul 5, 1:50 AM (10 h, 42 m)
Engine
blob
Format
Raw Data
Handle
679322
Attached To
D177: INP-1522 - Adapt error output for CLI
D177.diff
View Options
Index: branches/5.3.x/core/kernel/utility/logger.php
===================================================================
--- branches/5.3.x/core/kernel/utility/logger.php
+++ branches/5.3.x/core/kernel/utility/logger.php
@@ -645,13 +645,22 @@
$errstr = self::expandMessage($exception->getMessage(), !$this->_debugMode);
$this->_logRecord['LogLevel'] = self::LL_CRITICAL;
+ $exception_trace = $exception->getTrace();
+
+ array_unshift($exception_trace, array(
+ 'function' => '',
+ 'file' => $exception->getFile() !== null ? $exception->getFile() : 'n/a',
+ 'line' => $exception->getLine() !== null ? $exception->getLine() : 'n/a',
+ 'args' => array(),
+ ));
+
if ( $this->isLogType(self::LT_DATABASE, $errstr) ) {
list ($errno, $errstr, $sql) = self::parseDatabaseError($errstr);
$this->_logRecord['LogType'] = self::LT_DATABASE;
$this->_logRecord['LogUserData'] = $sql;
- $trace = $this->createTrace($exception->getTrace(), null, $this->_ignoreInTrace);
+ $trace = $this->createTrace($exception_trace, null, $this->_ignoreInTrace);
$this->addSource($trace);
$this->addTrace($trace, 0);
}
@@ -660,7 +669,7 @@
$errno = $exception->getCode();
$this->addSource((string)$exception->getFile(), $exception->getLine());
- $this->addTrace($exception->getTrace(), 0);
+ $this->addTrace($exception_trace, 0);
}
$this->_logRecord['LogCode'] = $errno;
@@ -908,12 +917,50 @@
$errfile = $this->_logRecord['LogSourceFilename'];
$errline = $this->_logRecord['LogSourceFileLine'];
- $result = '<strong>' . $errno . ': </strong>' . "{$errstr} in {$errfile} on line {$errline}";
+ if ( PHP_SAPI === 'cli' ) {
+ $result = sprintf(' [%s] ' . PHP_EOL . ' %s', $errno, $errstr);
+
+ if ( $this->_logRecord['LogBacktrace'] ) {
+ $result .= $this->printBacktrace(unserialize($this->_logRecord['LogBacktrace']));
+ }
+ }
+ else {
+ $result = '<strong>' . $errno . ': </strong>' . "{$errstr} in {$errfile} on line {$errline}";
+ }
return $strip_tags ? strip_tags($result) : $result;
}
/**
+ * Prints backtrace result
+ *
+ * @param array $trace Trace.
+ *
+ * @return string
+ */
+ protected function printBacktrace(array $trace)
+ {
+ if ( !$trace ) {
+ return '';
+ }
+
+ $ret = PHP_EOL . PHP_EOL . PHP_EOL . 'Exception trace:' . PHP_EOL;
+
+ foreach ( $trace as $trace_info ) {
+ $class = isset($trace_info['class']) ? $trace_info['class'] : '';
+ $type = isset($trace_info['type']) ? $trace_info['type'] : '';
+ $function = $trace_info['function'];
+ $args = isset($trace_info['args']) && $trace_info['args'] ? '...' : '';
+ $file = isset($trace_info['file']) ? $trace_info['file'] : 'n/a';
+ $line = isset($trace_info['line']) ? $trace_info['line'] : 'n/a';
+
+ $ret .= sprintf(' %s%s%s(%s) at %s:%s' . PHP_EOL, $class, $type, $function, $args, $file, $line);
+ }
+
+ return $ret;
+ }
+
+ /**
* Saves log to file (e.g. when not possible to save into database)
*
* @param $filename
@@ -1149,7 +1196,15 @@
$errno = $this->_getFatalErrorTitle($errno);
$margin = $this->Application->isAdmin ? '8px' : 'auto';
- echo '<div style="background-color: #FEFFBF; margin: ' . $margin . '; padding: 10px; border: 2px solid red; text-align: center">' . $this->_logger->toString($errno) . '</div>';
+ $error_msg = $this->_logger->toString($errno, PHP_SAPI === 'cli');
+
+ if ( PHP_SAPI === 'cli' ) {
+ echo $error_msg;
+ }
+ else {
+ echo '<div style="background-color: #FEFFBF; margin: ' . $margin . '; padding: 10px; border: 2px solid red; text-align: center">' . $error_msg . '</div>';
+ }
+
exit;
}
Event Timeline
Log In to Comment