diff --git a/paddle/fluid/framework/op_call_stack.cc b/paddle/fluid/framework/op_call_stack.cc index db259bf038ce16efe0a79451cbbd3245be8fcb9f..c3c56210b62aad2d18aacf6b3c075e22b3909994 100644 --- a/paddle/fluid/framework/op_call_stack.cc +++ b/paddle/fluid/framework/op_call_stack.cc @@ -46,19 +46,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs, } } // Step 2. Insert python traceback into err_str_ - std::size_t found = exception->err_str_.rfind("PaddleCheckError:"); + std::size_t found = exception->err_str_.rfind( + "\n----------------------\nError Message " + "Summary:\n----------------------\n"); if (found != std::string::npos) { exception->err_str_.insert(found, sout_py_trace.str()); - exception->err_str_.insert(found + sout_py_trace.str().length(), - "\n----------------------\nError Message " - "Summary:\n----------------------\n"); } else { exception->err_str_.append(sout_py_trace.str()); } - // Step 3. Construct final call stack - sout << "\n\n--------------------------------------------\n"; - sout << "C++ Call Stacks (More useful to developers):"; - sout << "\n--------------------------------------------\n"; + // Step 3. Construct final call stack & append error op name sout << exception->err_str_; if (callstack) { sout << " [operator < " << type << " > error]"; diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index db01414a8bb5486fd0812c70bdfc73ceaca630e4..a1dc1718327a415e451c65474a1ee52a9f07133d 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -74,6 +74,9 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, static constexpr int TRACE_STACK_LIMIT = 100; std::ostringstream sout; + sout << "\n\n--------------------------------------------\n"; + sout << "C++ Call Stacks (More useful to developers):"; + sout << "\n--------------------------------------------\n"; #if !defined(_WIN32) void* call_stack[TRACE_STACK_LIMIT]; auto size = backtrace(call_stack, TRACE_STACK_LIMIT); @@ -102,8 +105,10 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, } free(symbols); #else - sout << "Windows not support stack backtrace yet."; + sout << "Windows not support stack backtrace yet.\n"; #endif + sout << "\n----------------------\nError Message " + "Summary:\n----------------------\n"; sout << string::Sprintf("PaddleCheckError: %s at [%s:%d]", std::forward(what), file, line) << std::endl;