From 1aa0933309c7eceed81314aaff40551e15225981 Mon Sep 17 00:00:00 2001
From: Pawel Wasowski
Date: Mon, 18 Jan 2021 20:35:14 +0100
Subject: [PATCH] [common] Add std::exception handler to ParsedInstance
When an exception derived from std::exception and not PlatformException
is thrown in webapi-plugins code, only the following error message was
logged:
HandleException(393) > Exception: Unknown exception
As std::exception inheritance is a very common practice, especially in
standard library, we add logging std::exception::what() message to make
debugging easier.
[Verification] An exception thrown from std::string is caught and its
what() message is logged properly.
Change-Id: I879ebe80b609cf26a7e68be822a783aa9ef145eb
Signed-off-by: Pawel Wasowski
---
src/common/extension.cc | 11 +++++++++++
src/common/extension.h | 2 ++
2 files changed, 13 insertions(+)
diff --git a/src/common/extension.cc b/src/common/extension.cc
index 6a0a2c3..7a1be11 100644
--- a/src/common/extension.cc
+++ b/src/common/extension.cc
@@ -383,6 +383,8 @@ void ParsedInstance::HandleMessage(const char* msg, bool is_sync) {
return HandleException(e);
} catch (const PlatformException* e) {
return HandleException(*e);
+ } catch (const std::exception& e) {
+ return HandleException(e);
} catch (...) {
return HandleException(UnknownException("Unknown exception"));
}
@@ -396,6 +398,15 @@ void ParsedInstance::HandleException(const PlatformException& ex) {
SendSyncReply(result.serialize().c_str());
}
+void ParsedInstance::HandleException(const std::exception& e) {
+ ScopeLogger();
+ LoggerE("std::exception: %s", e.what());
+ picojson::value result = picojson::value(picojson::object());
+ ReportError(common::PlatformResult{common::ErrorCode::ABORT_ERR, "An unknown internal error"},
+ &result.get());
+ SendSyncReply(result.serialize().c_str());
+}
+
void ParsedInstance::HandleError(const PlatformResult& e) {
LoggerE("Error: %d", static_cast(e.error_code()));
picojson::value result = picojson::value(picojson::object());
diff --git a/src/common/extension.h b/src/common/extension.h
index 404e3f7..99f459e 100644
--- a/src/common/extension.h
+++ b/src/common/extension.h
@@ -19,6 +19,7 @@
#include
+#include
#include
#include