Skip to content

Commit

Permalink
feat: dump extension name in c++ exception handler (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn authored Nov 18, 2024
1 parent 0e8de3d commit 8a69f98
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 31 deletions.
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

0 comments on commit 8a69f98

Please sign in to comment.