From 5ffeb4c157ad7c03475664c4bd97d05c66e81fbf Mon Sep 17 00:00:00 2001 From: Hu Yueh-Wei Date: Mon, 18 Nov 2024 21:55:37 +0800 Subject: [PATCH] feat: dump extension name in c++ exception handler --- .../binding/cpp/internal/extension.h | 89 ++++++++++++------- .../extension/extension_a/extension.go | 3 +- 2 files changed, 61 insertions(+), 31 deletions(-) diff --git a/core/include/ten_runtime/binding/cpp/internal/extension.h b/core/include/ten_runtime/binding/cpp/internal/extension.h index 50bd24346a..ca7540f2c2 100644 --- a/core/include/ten_runtime/binding/cpp/internal/extension.h +++ b/core/include/ten_runtime/binding/cpp/internal/extension.h @@ -127,7 +127,7 @@ class extension_t { friend class extension_group_t; using cpp_extension_on_cmd_func_t = - void (extension_t::*)(ten_env_t &, std::unique_ptr); + void (extension_t:: *)(ten_env_t &, std::unique_ptr); static void issue_stop_graph_cmd(ten_env_t &ten_env) { // Issue a 'close engine' command, and in order to gain the maximum @@ -290,12 +290,16 @@ class extension_t { try { on_configure(ten_env); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_configure(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_configure()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGW("Caught a exception of type '%s' in extension on_configure().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, + (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_configure().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -314,12 +318,15 @@ class extension_t { try { on_init(ten_env); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_init(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_init()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGW("Caught a exception of type '%s' in extension on_init().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_init().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -338,12 +345,15 @@ class extension_t { try { on_start(ten_env); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_start(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_start()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGW("Caught a exception of type '%s' in extension on_start().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_start().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -362,12 +372,15 @@ class extension_t { try { on_stop(ten_env); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_stop(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_stop()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGD("Caught a exception '%s' in extension on_stop().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_stop().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -386,12 +399,15 @@ class extension_t { try { on_deinit(ten_env); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_deinit(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_deinit()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGD("Caught a exception '%s' in extension on_deinit().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_deinit().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -412,12 +428,16 @@ class extension_t { try { (this->*on_cmd_func)(ten_env, std::move(cmd)); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_cmd(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_cmd()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGE("Caught a exception '%s' in extension on_cmd().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_cmd().") + .c_str()); + issue_stop_graph_cmd(ten_env); } } @@ -436,12 +456,15 @@ class extension_t { try { on_data(ten_env, std::move(data)); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_data(), %s", e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_data()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGD("Caught a exception '%s' in extension on_data().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_data().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -461,13 +484,16 @@ class extension_t { try { on_audio_frame(ten_env, std::move(frame)); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_audio_frame(), %s", - e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_audio_frame()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGD("Caught a exception '%s' in extension on_audio_frame().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, + (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_audio_frame().") + .c_str()); issue_stop_graph_cmd(ten_env); } @@ -487,13 +513,16 @@ class extension_t { try { on_video_frame(ten_env, std::move(frame)); } catch (std::exception &e) { - TEN_LOGW("Caught a exception in extension on_video_frame(), %s", - e.what()); + TEN_ENV_LOG_WARN(ten_env, (std::string("Caught an exception '") + + e.what() + "' in on_video_frame()") + .c_str()); issue_stop_graph_cmd(ten_env); } catch (...) { - TEN_LOGD("Caught a exception '%s' in extension on_video_frame().", - curr_exception_type_name().c_str()); + TEN_ENV_LOG_WARN(ten_env, + (std::string("Caught an exception of type '") + + curr_exception_type_name() + "in on_video_frame().") + .c_str()); issue_stop_graph_cmd(ten_env); } diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go index 214a4db74f..b993514048 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_a/extension.go @@ -54,7 +54,8 @@ func (p *extensionA) OnStart(tenEnv ten.TenEnv) { panic("Should not happen") } - if em, err := tenEnv.GetPropertyString("empty_string"); err != nil || em != "" { + if em, err := tenEnv.GetPropertyString("empty_string"); err != nil || + em != "" { panic("Should not happen") } }