Don't escape exception error messages in command line mode

The main impetuous was "\" is the namespace character, so I want namespace errors to not have double backslashes everywhere.

After finding that, it turned out we were escaping all exceptions in the command line, which is wrong. We only want the escaping when we are in server mode (emulating apache)

I basically pushed what we were doing in ##error_log## down to ##Logger::Log##.
Esse commit está contido em:
Paul Tarjan
2013-05-16 01:04:08 -07:00
commit de Sara Golemon
commit ebf437281c
31 arquivos alterados com 153 adições e 99 exclusões
+22 -19
Ver Arquivo
@@ -583,12 +583,31 @@ static void pagein_self(void) {
free(buf);
}
/* Sets RuntimeOption::ExecutionMode according
* to commandline options prior to config load
*/
static void set_execution_mode(string mode) {
if (mode == "daemon" || mode == "server" || mode == "replay") {
RuntimeOption::ExecutionMode = "srv";
Logger::Escape = true;
} else if (mode == "run" || mode == "debug") {
RuntimeOption::ExecutionMode = "cli";
Logger::Escape = false;
} else if (mode == "translate") {
RuntimeOption::ExecutionMode = "";
Logger::Escape = false;
} else {
// Undefined mode
always_assert(false);
}
}
static int start_server(const std::string &username) {
// Before we start the webserver, make sure the entire
// binary is paged into memory.
pagein_self();
RuntimeOption::ExecutionMode = "srv";
set_execution_mode("server");
HttpRequestHandler::GetAccessLog().init
(RuntimeOption::AccessLogDefaultFormat, RuntimeOption::AccessLogs,
username);
@@ -762,22 +781,6 @@ static void close_server_log_file(int kind) {
}
}
/* Sets RuntimeOption::ExecutionMode according
* to commandline options prior to config load
*/
static void set_execution_mode(string mode) {
if (mode == "daemon" || mode == "server" || mode == "replay") {
RuntimeOption::ExecutionMode = "srv";
} else if (mode == "run" || mode == "debug") {
RuntimeOption::ExecutionMode = "cli";
} else if (mode == "translate") {
RuntimeOption::ExecutionMode = "";
} else {
// Undefined mode
always_assert(false);
}
}
static int execute_program_impl(int argc, char **argv) {
string usage = "Usage:\n\n\t";
usage += argv[0];
@@ -1030,7 +1033,7 @@ static int execute_program_impl(int argc, char **argv) {
tempFile = po.file;
}
RuntimeOption::ExecutionMode = "cli";
set_execution_mode("run");
int new_argc;
char **new_argv;
@@ -1113,7 +1116,7 @@ static int execute_program_impl(int argc, char **argv) {
if (po.mode == "replay" && !po.args.empty()) {
RuntimeOption::RecordInput = false;
RuntimeOption::ExecutionMode = "srv";
set_execution_mode("server");
HttpServer server; // so we initialize runtime properly
HttpRequestHandler handler;
for (int i = 0; i < po.count; i++) {
+1 -9
Ver Arquivo
@@ -51,15 +51,7 @@
} \
} \
Logger::Log(Log ## LOGLEVEL, msg, nullptr, true); \
} \
void ExtendedLogger::Raw ## LOGLEVEL(const std::string &msg) { \
if (LogLevel < Log ## LOGLEVEL) return; \
Logger::Log(Log ## LOGLEVEL, msg, nullptr, false); \
if (RuntimeOption::InjectedStackTrace && \
!ExtendedLogger::EnabledByDefault) { \
Log(Log ## LOGLEVEL, g_vmContext->debugBacktrace()); \
} \
} \
}
namespace HPHP {
-6
Ver Arquivo
@@ -39,12 +39,6 @@ public:
static void Info(const char *fmt, ...);
static void Verbose(const char *fmt, ...);
// Log messages without escaping.
static void RawError(const std::string &msg);
static void RawWarning(const std::string &msg);
static void RawInfo(const std::string &msg);
static void RawVerbose(const std::string &msg);
// Log additional injected stacktrace.
static void Log(LogLevelType level, CArrRef stackTrace, bool escape = true,
bool escapeMore = false);
+6 -9
Ver Arquivo
@@ -17,7 +17,6 @@
#include "hphp/runtime/ext/ext_error.h"
#include "hphp/runtime/base/util/exceptions.h"
#include "hphp/runtime/base/runtime_option.h"
#include "hphp/runtime/base/util/string_buffer.h"
#include "hphp/util/logger.h"
@@ -108,17 +107,15 @@ bool f_error_log(CStrRef message, int message_type /* = 0 */,
std::string line(message.data(),
// Truncate to 512k
message.size() > (1<<19) ? (1<<19) : message.size());
if (RuntimeOption::ServerExecutionMode() ||
RuntimeOption::AlwaysEscapeLog) {
Logger::Error(line);
} else {
Logger::RawError(line);
Logger::Error(line);
if (!RuntimeOption::ServerExecutionMode() &&
Logger::UseLogFile && Logger::Output) {
// otherwise errors will go to error log without displaying on screen
if (Logger::UseLogFile && Logger::Output) {
std::cerr << line;
}
std::cerr << line;
}
return true;
}
@@ -1 +1,3 @@
HipHop Fatal error: Uncaught exception 'Exception' with message '55' in %s:55\nStack trace:\n#0 {main}
HipHop Fatal error: Uncaught exception 'Exception' with message '55' in %s/test/quick/debug_backtrace_multiline.php:55
Stack trace:
#0 {main}
@@ -3,5 +3,11 @@ main() starting
Calling foo()
Calling bar()
In ThrowDestruct2::__destruct()
HipHop Warning: Destructor threw an object exception: exception 'Ex2' with message 'Exception leaked out of ThrowDestruct2::__destruct()' in %a on line %d
HipHop Warning: Destructor threw an object exception: exception 'Ex2' with message 'Exception leaked out of ThrowDestruct2::__destruct()' in %s/test/quick/exception_destructor_3.php:23
Stack trace:
#0 %s/test/quick/exception_destructor_3.php(%d): ThrowDestruct2->__destruct()
#1 %s/test/quick/exception_destructor_3.php(43): bar()
#2 %s/test/quick/exception_destructor_3.php(64): foo()
#3 %s/test/quick/exception_destructor_3.php(76): main()
#4 {main} in %s/test/quick/exception_destructor_3.php on line %d
After bar()
@@ -4,4 +4,9 @@ Calling foo()
Calling bar()
Throwing in bar()
In ExitDestruct::__destruct()
HipHop Fatal error: Uncaught exception 'Exception' with message 'Exception from bar()' in %a
HipHop Fatal error: Uncaught exception 'Exception' with message 'Exception from bar()' in %s/test/quick/exception_destructor_4.php:40
Stack trace:
#0 %s/test/quick/exception_destructor_4.php(46): bar()
#1 %s/test/quick/exception_destructor_4.php(63): foo()
#2 %s/test/quick/exception_destructor_4.php(75): main()
#3 {main}
+8 -2
Ver Arquivo
@@ -1,2 +1,8 @@
HipHop Fatal error: Uncaught exception 'Exception' with message 'throwing first' in %s:9\nStack trace:\n#0 %s(11): main()\n#1 {main}
Exception handler threw an object exception: exception 'Exception' with message 'throwing second' in %s:4\nStack trace:\n#0 (): exn_throw()\n#1 {main}
HipHop Fatal error: Uncaught exception 'Exception' with message 'throwing first' in %s/test/quick/exception_handler.php:9
Stack trace:
#0 %s/test/quick/exception_handler.php(11): main()
#1 {main}
Exception handler threw an object exception: exception 'Exception' with message 'throwing second' in %s/test/quick/exception_handler.php:4
Stack trace:
#0 (): exn_throw()
#1 {main}
+22 -14
Ver Arquivo
@@ -6,23 +6,31 @@ caught 2
before
caught
caught exception
string(%d) "#0 %s(91): c()
#1 %s(88): b()
#2 %s(99): a()
#3 %s(111): main3()
string(%d) "#0 %s/test/quick/exceptions.php(91): c()
#1 %s/test/quick/exceptions.php(88): b()
#2 %s/test/quick/exceptions.php(99): a()
#3 %s/test/quick/exceptions.php(111): main3()
#4 {main}"
string(16) "hello, exception"
string(%d) "#0 %s(91): c()
#1 %s(88): b()
#2 %s(99): a()
#3 %s(111): main3()
string(%d) "#0 %s/test/quick/exceptions.php(91): c()
#1 %s/test/quick/exceptions.php(88): b()
#2 %s/test/quick/exceptions.php(99): a()
#3 %s/test/quick/exceptions.php(111): main3()
#4 {main}"
Exception from %s:96
string(%d) "#0 %s(91): c()
#1 %s(88): b()
#2 %s(99): a()
#3 %s(111): main3()
Exception from %s/test/quick/exceptions.php:96
string(%d) "#0 %s/test/quick/exceptions.php(91): c()
#1 %s/test/quick/exceptions.php(88): b()
#2 %s/test/quick/exceptions.php(99): a()
#3 %s/test/quick/exceptions.php(111): main3()
#4 {main}"
bar 3
caught 3
HipHop Fatal error: Uncaught exception 'Ex3' with message '' in %s:21\nStack trace:\n#0 %s(28): bar()\n#1 %s(35): foo2()\n#2 %s(39): foo1()\n#3 (): foo()\n#4 %s(105): array_map()\n#5 %s(111): main3()\n#6 {main}
HipHop Fatal error: Uncaught exception 'Ex3' with message '' in %s/test/quick/exceptions.php:21
Stack trace:
#0 %s/test/quick/exceptions.php(28): bar()
#1 %s/test/quick/exceptions.php(35): foo2()
#2 %s/test/quick/exceptions.php(39): foo1()
#3 (): foo()
#4 %s/test/quick/exceptions.php(105): array_map()
#5 %s/test/quick/exceptions.php(111): main3()
#6 {main}
+8 -2
Ver Arquivo
@@ -1,2 +1,8 @@
HipHop Warning: Destructor threw an object exception: exception 'Exception' with message '' in %s on line 21
HipHop Fatal error: Uncaught exception 'Exception' with message '' in %s:5\nStack trace:\n#0 %s(21): A->__construct()\n#1 {main}
HipHop Warning: Destructor threw an object exception: exception 'Exception' with message '' in %s/test/quick/exceptions4.php:11
Stack trace:
#0 %s/test/quick/exceptions4.php(21): B->__destruct()
#1 {main} in %s/test/quick/exceptions4.php on line 21
HipHop Fatal error: Uncaught exception 'Exception' with message '' in %s/test/quick/exceptions4.php:5
Stack trace:
#0 %s/test/quick/exceptions4.php(21): A->__construct()
#1 {main}
+3 -1
Ver Arquivo
@@ -1 +1,3 @@
HipHop Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function bar() on a non-object' in %s:4\nStack trace:\n#0 {main}
HipHop Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function bar() on a non-object' in %s/test/quick/method-non-object.php:4
Stack trace:
#0 {main}
+3 -1
Ver Arquivo
@@ -1 +1,3 @@
HipHop Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function bar() on a non-object' in %s:5\nStack trace:\n#0 {main}
HipHop Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function bar() on a non-object' in %s/test/quick/method-non-object2.php:5
Stack trace:
#0 {main}
@@ -1,3 +1,5 @@
Error handler
We hit our handler.
HipHop Fatal error: Uncaught exception 'Exception' with message 'Sup' in %s:20\nStack trace:\n#0 {main}
HipHop Fatal error: Uncaught exception 'Exception' with message 'Sup' in %s/test/quick/nested_vm_exceptions.php:20
Stack trace:
#0 {main}
@@ -1,3 +1,5 @@
Error handler
We hit our handler.
HipHop Fatal error: Uncaught exception 'Exception' with message 'Sup' in %s:26\nStack trace:\n#0 {main}
HipHop Fatal error: Uncaught exception 'Exception' with message 'Sup' in %s/test/quick/nested_vm_exceptions2.php:26
Stack trace:
#0 {main}
+9 -4
Ver Arquivo
@@ -1,8 +1,13 @@
one
HipHop Warning: two() expects exactly 2 parameters, 1 given in %s on line 4
HipHop Warning: two() expects exactly 2 parameters, 1 given in %s/test/quick/not-enough-args.php on line 4
two
HipHop Warning: three() expects exactly 3 parameters, 1 given in %s on line 5
HipHop Warning: three() expects exactly 3 parameters, 2 given in %s on line 5
HipHop Warning: three() expects exactly 3 parameters, 1 given in %s/test/quick/not-enough-args.php on line 5
HipHop Warning: three() expects exactly 3 parameters, 2 given in %s/test/quick/not-enough-args.php on line 5
three
one
HipHop Fatal error: Uncaught exception 'Exception' with message '2, two() expects exactly 2 parameters, 1 given' in %s:8\nStack trace:\n#0 %s(4): error_handler()\n#1 %s(17): two()\n#2 %s(20): main()\n#3 {main}
HipHop Fatal error: Uncaught exception 'Exception' with message '2, two() expects exactly 2 parameters, 1 given' in %s/test/quick/not-enough-args.php:8
Stack trace:
#0 %s/test/quick/not-enough-args.php(4): error_handler()
#1 %s/test/quick/not-enough-args.php(17): two()
#2 %s/test/quick/not-enough-args.php(20): main()
#3 {main}
@@ -1 +1 @@
HipHop Fatal error: Cannot use A\\Cl as Cl because the name is already in use: (Line: 8, Char: 9) in %s on line 8
HipHop Fatal error: Cannot use A\Cl as Cl because the name is already in use: (Line: 8, Char: 9) in %s on line 8
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Call to undefined function B\\f() in %s on line 7
HipHop Fatal error: Call to undefined function B\f() in %s on line 7
+6 -1
Ver Arquivo
@@ -2,4 +2,9 @@ wat
~something
HipHop Notice: Undefined index: object in %s on line 10
NULL
HipHop Fatal error: Uncaught exception 'Exception' with message 'asd' in %s
HipHop Fatal error: Uncaught exception 'Exception' with message 'asd' in %s/hphp/test/quick/unwind_backtrace.php:4
Stack trace:
#0 %s/hphp/test/quick/unwind_backtrace.php(22): blah()
#1 %s/hphp/test/quick/unwind_backtrace.php(28): Bar->foo()
#2 %s/hphp/test/quick/unwind_backtrace.php(31): main()
#3 {main}
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/702.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/702.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/704.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/704.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/706.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/706.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/708.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/708.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/710.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/710.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/712.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/712.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/714.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/714.php on line 4
+1 -1
Ver Arquivo
@@ -1 +1 @@
HipHop Fatal error: Cannot access property started with '\\0' in %s/hphp/test/slow/object_property/716.php on line 4
HipHop Fatal error: Cannot access property started with '\0' in %s/hphp/test/slow/object_property/716.php on line 4
Arquivo executável
+19
Ver Arquivo
@@ -0,0 +1,19 @@
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import re
import sys
for test in sys.argv[1:]:
if not test.endswith('.php'):
print ("%s doesn\'t end in .php. All tests should" % test)
sys.exit(1)
data = file(test + '.out').read()
data = re.sub('/data[^ ]*/hphp', '%s', data)
file(test + '.expectf', 'w').write(data)
print ('Copied %s.out to %s.expectf' % (test, test))
+11 -9
Ver Arquivo
@@ -23,7 +23,7 @@
#include "hphp/util/text_color.h"
#include <syslog.h>
#define IMPLEMENT_LOGLEVEL(LOGLEVEL) \
#define IMPLEMENT_LOGLEVEL(LOGLEVEL) \
void Logger::LOGLEVEL(const char *fmt, ...) { \
if (LogLevel < Log ## LOGLEVEL) return; \
va_list ap; va_start(ap, fmt); \
@@ -32,12 +32,8 @@
} \
void Logger::LOGLEVEL(const std::string &msg) { \
if (LogLevel < Log ## LOGLEVEL) return; \
Log(Log ## LOGLEVEL, msg, nullptr); \
} \
void Logger::Raw ## LOGLEVEL(const std::string &msg) { \
if (LogLevel < Log ## LOGLEVEL) return; \
Log(Log ## LOGLEVEL, msg, nullptr, false); \
} \
Log(Log ## LOGLEVEL, msg, nullptr); \
}
namespace HPHP {
@@ -64,6 +60,7 @@ bool Logger::LogHeader = false;
bool Logger::LogNativeStackTrace = true;
std::string Logger::ExtraHeader;
int Logger::MaxMessagesPerRequest = -1;
bool Logger::Escape = true;
IMPLEMENT_THREAD_LOCAL(Logger::ThreadData, Logger::s_threadData);
Logger *Logger::s_logger = new Logger();
@@ -117,7 +114,7 @@ void Logger::ResetRequestCount() {
void Logger::Log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = true */, bool escapeMore /* = false */) {
bool escape /* = false */, bool escapeMore /* = false */) {
s_logger->log(level, msg, stackTrace, escape, escapeMore);
}
@@ -137,8 +134,13 @@ int Logger::GetSyslogLevel(LogLevelType level) {
void Logger::log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape /* = true */, bool escapeMore /* = false */) {
bool escape /* = false */, bool escapeMore /* = false */) {
if (Logger::Escape) {
escape = true;
}
assert(!escapeMore || escape);
ThreadData *threadData = s_threadData.get();
if (++threadData->message > MaxMessagesPerRequest &&
MaxMessagesPerRequest >= 0) {
+3 -7
Ver Arquivo
@@ -77,6 +77,7 @@ public:
static bool LogNativeStackTrace;
static std::string ExtraHeader;
static int MaxMessagesPerRequest;
static bool Escape;
static void Error(const std::string &msg);
static void Warning(const std::string &msg);
@@ -88,11 +89,6 @@ public:
static void Info(const char *fmt, ...);
static void Verbose(const char *fmt, ...);
// log messages without escaping
static void RawError(const std::string &msg);
static void RawWarning(const std::string &msg);
static void RawInfo(const std::string &msg);
static void RawVerbose(const std::string &msg);
static void Log(LogLevelType level, const char *type, const Exception &e,
const char *file = nullptr, int line = 0);
static void OnNewRequest();
@@ -138,7 +134,7 @@ protected:
static void LogEscapeMore(LogLevelType level, const char *fmt, va_list ap);
static void Log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape = true, bool escapeMore = false);
bool escape = false, bool escapeMore = false);
static inline bool IsEnabled() {
return Logger::UseLogFile || Logger::UseSyslog;
@@ -154,7 +150,7 @@ protected:
const char *file = nullptr, int line = 0);
virtual void log(LogLevelType level, const std::string &msg,
const StackTrace *stackTrace,
bool escape = true, bool escapeMore = false);
bool escape = false, bool escapeMore = false);
/**
* What needs to be print for each line of logging. Currently it's