Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dump extension name in c++ exception handler #292

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 59 additions & 30 deletions core/include/ten_runtime/binding/cpp/internal/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<cmd_t>);
void (extension_t:: *)(ten_env_t &, std::unique_ptr<cmd_t>);

static void issue_stop_graph_cmd(ten_env_t &ten_env) {
// Issue a 'close engine' command, and in order to gain the maximum
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Loading