From 873c007934a48ae73bd6299f1a506939a69cccb9 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 2 Sep 2020 09:47:09 -0700 Subject: [PATCH] Log exception in addition to the stack trace for unhandled exceptions. (#20935) * Log exception in addition to the stack trace for unhandled exceptions. Having exception logged can be especially useful when stack trace is blank. --- third_party/tonic/logging/dart_error.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/tonic/logging/dart_error.cc b/third_party/tonic/logging/dart_error.cc index 1f7863a0aedb7..e3e8343e93b8c 100644 --- a/third_party/tonic/logging/dart_error.cc +++ b/third_party/tonic/logging/dart_error.cc @@ -14,10 +14,14 @@ const char kInvalidArgument[] = "Invalid argument."; bool LogIfError(Dart_Handle handle) { if (Dart_IsUnhandledExceptionError(handle)) { + Dart_Handle exception_handle = Dart_ErrorGetException(handle); + const std::string exception = + tonic::StdStringFromDart(Dart_ToString(exception_handle)); Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle); const std::string stack_trace = tonic::StdStringFromDart(Dart_ToString(stack_trace_handle)); - tonic::Log("Dart Unhandled Exception: %s", stack_trace.c_str()); + tonic::Log("Dart Unhandled Exception: %s, stack trace: %s", + exception.c_str(), stack_trace.c_str()); return true; } else if (Dart_IsError(handle)) { tonic::Log("Dart Error: %s", Dart_GetError(handle));