From f0dc3af87969d0ffb74c17bbcb765e7f7e8e929e Mon Sep 17 00:00:00 2001 From: sunxilin Date: Mon, 2 Dec 2024 17:18:43 +0800 Subject: [PATCH] feat: add error handler for return_xxx --- .../ten_runtime/binding/cpp/detail/ten_env.h | 62 ++++++- .../ten_runtime/ten_env/internal/return.h | 19 ++- .../go/ten_env/ten_env_return_result.h | 16 -- .../binding/go/interface/ten/ten_env.go | 4 +- .../binding/go/interface/ten/ten_env.h | 6 +- .../go/interface/ten/ten_env_return.go | 34 +++- .../go/native/ten_env/ten_env_return_result.c | 156 +++++++++++------- .../native/ten_env/ten_env_return_result.c | 5 +- core/src/ten_runtime/extension/extension.c | 5 +- core/src/ten_runtime/extension/msg_handling.c | 3 +- .../src/ten_runtime/ten_env/internal/return.c | 41 +++-- .../default_extension_go/extension.go | 2 +- .../default_extension_go/extension.go.tent | 2 +- .../simple_http_server_go/main.go | 2 +- .../extension/extension_a/extension.go | 2 +- .../extension/extension_a/extension.go | 4 +- .../extension/extension_b/extension.go | 2 +- .../extension/extension_a/extension.go | 8 +- .../extension/extension_b/extension.go | 6 +- .../extension/extension_a/extension.go | 4 +- .../extension/extension_b/extension.go | 4 +- .../extension/extension_a/extension.go | 2 +- .../extension/extension_a/extension.go | 2 +- .../extension/extension_b/extension.go | 6 +- .../extension/extension_c/extension.go | 6 +- .../extension/extension_a/extension.go | 8 +- .../extension/extension_b/extension.go | 4 +- .../extension/extension_a/extension.go | 4 +- .../extension/extension_b/extension.go | 2 +- .../extension/extension_a/extension.go | 2 +- .../extension/extension_b/extension.go | 2 +- .../extension/extension_c/extension.go | 2 +- .../extension/extension_a/extension.go | 4 +- .../extension/extension_b/extension.go | 2 +- .../extension/addon_a/extension.go | 2 +- 35 files changed, 277 insertions(+), 158 deletions(-) delete mode 100644 core/include_internal/ten_runtime/binding/go/ten_env/ten_env_return_result.h diff --git a/core/include/ten_runtime/binding/cpp/detail/ten_env.h b/core/include/ten_runtime/binding/cpp/detail/ten_env.h index 0f8ce74955..19e052e1b1 100644 --- a/core/include/ten_runtime/binding/cpp/detail/ten_env.h +++ b/core/include/ten_runtime/binding/cpp/detail/ten_env.h @@ -201,18 +201,51 @@ class ten_env_t { return rc; } + static void proxy_handle_return_error(::ten_env_t *ten_env, void *user_data, + ::ten_error_t *err) { + TEN_ASSERT(ten_env, "Should not happen."); + + auto *error_handler = static_cast(user_data); + auto *cpp_ten_env = + static_cast(ten_binding_handle_get_me_in_target_lang( + reinterpret_cast(ten_env))); + + if (err != nullptr) { + error_t cpp_err(err, false); + (*error_handler)(*cpp_ten_env, &cpp_err); + } else { + (*error_handler)(*cpp_ten_env, nullptr); + } + + delete error_handler; + } + // If the 'cmd' has already been a command in the backward path, a extension // could use this API to return the 'cmd' further. bool return_result_directly(std::unique_ptr &&cmd, + error_handler_func_t &&error_handler = nullptr, error_t *err = nullptr) { if (!cmd) { TEN_ASSERT(0, "Invalid argument."); return false; } - auto rc = ten_env_return_result_directly( - c_ten_env, cmd->get_underlying_msg(), - err != nullptr ? err->get_c_error() : nullptr); + bool rc = false; + if (error_handler == nullptr) { + rc = ten_env_return_result_directly( + c_ten_env, cmd->get_underlying_msg(), nullptr, nullptr, + err != nullptr ? err->get_c_error() : nullptr); + } else { + auto *error_handler_ptr = + new error_handler_func_t(std::move(error_handler)); + + rc = ten_env_return_result_directly( + c_ten_env, cmd->get_underlying_msg(), proxy_handle_return_error, + error_handler_ptr, err != nullptr ? err->get_c_error() : nullptr); + if (!rc) { + delete error_handler_ptr; + } + } if (rc) { // The 'cmd' has been returned, so we should release the ownership of @@ -228,6 +261,7 @@ class ten_env_t { bool return_result(std::unique_ptr &&cmd, std::unique_ptr &&target_cmd, + error_handler_func_t &&error_handler = nullptr, error_t *err = nullptr) { if (!cmd) { TEN_ASSERT(0, "Invalid argument."); @@ -238,9 +272,25 @@ class ten_env_t { return false; } - auto rc = ten_env_return_result( - c_ten_env, cmd->get_underlying_msg(), target_cmd->get_underlying_msg(), - err != nullptr ? err->get_c_error() : nullptr); + bool rc = false; + + if (error_handler == nullptr) { + rc = ten_env_return_result(c_ten_env, cmd->get_underlying_msg(), + target_cmd->get_underlying_msg(), nullptr, + nullptr, + err != nullptr ? err->get_c_error() : nullptr); + } else { + auto *error_handler_ptr = + new error_handler_func_t(std::move(error_handler)); + + rc = ten_env_return_result(c_ten_env, cmd->get_underlying_msg(), + target_cmd->get_underlying_msg(), + proxy_handle_return_error, error_handler_ptr, + err != nullptr ? err->get_c_error() : nullptr); + if (!rc) { + delete error_handler_ptr; + } + } if (rc) { if (cmd->is_final()) { diff --git a/core/include/ten_runtime/ten_env/internal/return.h b/core/include/ten_runtime/ten_env/internal/return.h index 5ca84a0f33..c0ba5ccfe0 100644 --- a/core/include/ten_runtime/ten_env/internal/return.h +++ b/core/include/ten_runtime/ten_env/internal/return.h @@ -14,11 +14,16 @@ #include "ten_utils/lib/error.h" #include "ten_utils/lib/smart_ptr.h" -TEN_RUNTIME_API bool ten_env_return_result(ten_env_t *self, - ten_shared_ptr_t *result, - ten_shared_ptr_t *target_cmd, - ten_error_t *err); +typedef void (*ten_env_return_result_error_handler_func_t)(ten_env_t *self, + void *user_data, + ten_error_t *err); -TEN_RUNTIME_API bool ten_env_return_result_directly(ten_env_t *self, - ten_shared_ptr_t *cmd, - ten_error_t *err); +TEN_RUNTIME_API bool ten_env_return_result( + ten_env_t *self, ten_shared_ptr_t *result, ten_shared_ptr_t *target_cmd, + ten_env_return_result_error_handler_func_t error_handler, + void *error_handler_data, ten_error_t *err); + +TEN_RUNTIME_API bool ten_env_return_result_directly( + ten_env_t *self, ten_shared_ptr_t *cmd, + ten_env_return_result_error_handler_func_t error_handler, + void *error_handler_data, ten_error_t *err); diff --git a/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_return_result.h b/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_return_result.h deleted file mode 100644 index 361daf92fe..0000000000 --- a/core/include_internal/ten_runtime/binding/go/ten_env/ten_env_return_result.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright © 2024 Agora -// This file is part of TEN Framework, an open source project. -// Licensed under the Apache License, Version 2.0, with certain conditions. -// Refer to the "LICENSE" file in the root directory for more information. -// -#include "ten_runtime/ten_config.h" - -#include "ten_runtime/binding/go/interface/ten/common.h" -#include "ten_runtime/binding/go/interface/ten/ten_env.h" -#include "ten_runtime/common/status_code.h" -#include "ten_utils/value/value.h" - -TEN_RUNTIME_PRIVATE_API bool ten_go_ten_return_status_value( - ten_go_ten_env_t *self, ten_go_msg_t *cmd, TEN_STATUS_CODE status_code, - ten_value_t *status_value, ten_go_error_t *api_status); diff --git a/core/src/ten_runtime/binding/go/interface/ten/ten_env.go b/core/src/ten_runtime/binding/go/interface/ten/ten_env.go index 722481f975..5adf7d151a 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/ten_env.go +++ b/core/src/ten_runtime/binding/go/interface/ten/ten_env.go @@ -33,8 +33,8 @@ type TenEnv interface { SendVideoFrame(videoFrame VideoFrame, handler ErrorHandler) error SendAudioFrame(audioFrame AudioFrame, handler ErrorHandler) error - ReturnResult(result CmdResult, cmd Cmd) error - ReturnResultDirectly(result CmdResult) error + ReturnResult(result CmdResult, cmd Cmd, handler ErrorHandler) error + ReturnResultDirectly(result CmdResult, handler ErrorHandler) error OnConfigureDone() error OnInitDone() error diff --git a/core/src/ten_runtime/binding/go/interface/ten/ten_env.h b/core/src/ten_runtime/binding/go/interface/ten/ten_env.h index f3887de0df..6b1122ec40 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/ten_env.h +++ b/core/src/ten_runtime/binding/go/interface/ten/ten_env.h @@ -37,10 +37,12 @@ void ten_go_ten_env_on_create_instance_done(uintptr_t bridge_addr, ten_go_error_t ten_go_ten_env_return_result(uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr, - uintptr_t cmd_bridge_addr); + uintptr_t cmd_bridge_addr, + ten_go_handle_t handler_id); ten_go_error_t ten_go_ten_env_return_result_directly( - uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr); + uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr, + ten_go_handle_t handler_id); ten_go_error_t ten_go_ten_env_send_cmd(uintptr_t bridge_addr, uintptr_t cmd_bridge_addr, diff --git a/core/src/ten_runtime/binding/go/interface/ten/ten_env_return.go b/core/src/ten_runtime/binding/go/interface/ten/ten_env_return.go index 5b21f05583..ebc97dede5 100644 --- a/core/src/ten_runtime/binding/go/interface/ten/ten_env_return.go +++ b/core/src/ten_runtime/binding/go/interface/ten/ten_env_return.go @@ -10,7 +10,7 @@ package ten //#include "ten_env.h" import "C" -func (p *tenEnv) ReturnResult(statusCmd CmdResult, cmd Cmd) error { +func (p *tenEnv) ReturnResult(statusCmd CmdResult, cmd Cmd, handler ErrorHandler) error { if statusCmd == nil { return newTenError( ErrnoInvalidArgument, @@ -25,23 +25,36 @@ func (p *tenEnv) ReturnResult(statusCmd CmdResult, cmd Cmd) error { ) } + cb := goHandleNil + if handler != nil { + cb = newGoHandle(handler) + } + defer func() { p.keepAlive() cmd.keepAlive() statusCmd.keepAlive() }() - return withCGO(func() error { + err := withCGO(func() error { apiStatus := C.ten_go_ten_env_return_result( p.cPtr, statusCmd.getCPtr(), cmd.getCPtr(), + cHandle(cb), ) return withCGoError(&apiStatus) }) + + if err != nil { + // Clean up the handle if there was an error. + loadAndDeleteGoHandle(cb) + } + + return err } -func (p *tenEnv) ReturnResultDirectly(statusCmd CmdResult) error { +func (p *tenEnv) ReturnResultDirectly(statusCmd CmdResult, handler ErrorHandler) error { if statusCmd == nil { return newTenError( ErrnoInvalidArgument, @@ -54,11 +67,24 @@ func (p *tenEnv) ReturnResultDirectly(statusCmd CmdResult) error { statusCmd.keepAlive() }() - return withCGO(func() error { + cb := goHandleNil + if handler != nil { + cb = newGoHandle(handler) + } + + err := withCGO(func() error { apiStatus := C.ten_go_ten_env_return_result_directly( p.cPtr, statusCmd.getCPtr(), + cHandle(cb), ) return withCGoError(&apiStatus) }) + + if err != nil { + // Clean up the handle if there was an error. + loadAndDeleteGoHandle(cb) + } + + return err } diff --git a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c index ad5e395381..ea4dcc1f41 100644 --- a/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c +++ b/core/src/ten_runtime/binding/go/native/ten_env/ten_env_return_result.c @@ -23,17 +23,20 @@ #include "ten_runtime/ten_env_proxy/ten_env_proxy.h" #include "ten_utils/lib/alloc.h" #include "ten_utils/lib/error.h" +#include "ten_utils/log/log.h" #include "ten_utils/macro/check.h" #include "ten_utils/value/value.h" typedef struct ten_env_notify_return_result_info_t { ten_shared_ptr_t *c_cmd; ten_shared_ptr_t *c_target_cmd; + ten_go_handle_t handler_id; } ten_env_notify_return_result_info_t; static ten_env_notify_return_result_info_t * ten_env_notify_return_result_info_create(ten_shared_ptr_t *c_cmd, - ten_shared_ptr_t *c_target_cmd) { + ten_shared_ptr_t *c_target_cmd, + ten_go_handle_t handler_id) { TEN_ASSERT(c_cmd, "Invalid argument."); ten_env_notify_return_result_info_t *info = @@ -42,6 +45,7 @@ ten_env_notify_return_result_info_create(ten_shared_ptr_t *c_cmd, info->c_cmd = c_cmd; info->c_target_cmd = c_target_cmd; + info->handler_id = handler_id; return info; } @@ -60,9 +64,37 @@ static void ten_env_notify_return_result_info_destroy( info->c_target_cmd = NULL; } + info->handler_id = 0; + TEN_FREE(info); } +static void proxy_handle_return_error(ten_env_t *ten_env, void *user_data, + ten_error_t *err) { + TEN_ASSERT(ten_env && ten_env_check_integrity(ten_env, true), + "Should not happen."); + + ten_go_callback_info_t *callback_info = user_data; + TEN_ASSERT(callback_info, "Should not happen."); + + ten_go_error_t cgo_error; + ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); + + if (err) { + ten_go_error_from_error(&cgo_error, err); + } + + TEN_ASSERT(callback_info->callback_id != TEN_GO_NO_RESPONSE_HANDLER, + "Should not happen."); + + ten_go_ten_env_t *ten_env_bridge = ten_go_ten_env_wrap(ten_env); + + tenGoOnError(ten_env_bridge->bridge.go_instance, callback_info->callback_id, + cgo_error); + + ten_go_callback_info_destroy(callback_info); +} + static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, void *user_data) { TEN_ASSERT(user_data, "Invalid argument."); @@ -70,17 +102,57 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, "Should not happen."); ten_env_notify_return_result_info_t *info = user_data; + TEN_ASSERT(info, "Should not happen."); + + ten_go_error_t cgo_error; + ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); ten_error_t err; ten_error_init(&err); bool rc = false; - if (info->c_target_cmd) { - rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, &err); - TEN_ASSERT(rc, "Should not happen."); + if (info->handler_id == TEN_GO_NO_RESPONSE_HANDLER) { + if (info->c_target_cmd) { + rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, NULL, + NULL, &err); + TEN_ASSERT(rc, "Should not happen."); + } else { + rc = ten_env_return_result_directly(ten_env, info->c_cmd, NULL, NULL, + &err); + TEN_ASSERT(rc, "Should not happen."); + } + + if (!rc) { + // The error cannot be handled by the developer, all we can do is to log + // the error. + TEN_LOGE( + "Failed to return result to Go, but no error handler is provided. " + "errno: %d, errmsg: %s", + ten_error_errno(&err), ten_error_errmsg(&err)); + } } else { - rc = ten_env_return_result_directly(ten_env, info->c_cmd, &err); - TEN_ASSERT(rc, "Should not happen."); + ten_go_callback_info_t *callback_info = + ten_go_callback_info_create(info->handler_id); + if (info->c_target_cmd) { + rc = + ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, + proxy_handle_return_error, callback_info, &err); + } else { + rc = ten_env_return_result_directly( + ten_env, info->c_cmd, proxy_handle_return_error, callback_info, &err); + } + + if (!rc) { + // Prepare error information to pass to Go. + ten_go_error_from_error(&cgo_error, &err); + + ten_go_ten_env_t *ten_env_bridge = ten_go_ten_env_wrap(ten_env); + + tenGoOnError(ten_env_bridge->bridge.go_instance, info->handler_id, + cgo_error); + + ten_go_callback_info_destroy(callback_info); + } } ten_error_deinit(&err); @@ -90,7 +162,8 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, ten_go_error_t ten_go_ten_env_return_result(uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr, - uintptr_t cmd_bridge_addr) { + uintptr_t cmd_bridge_addr, + ten_go_handle_t handler_id) { ten_go_ten_env_t *self = ten_go_ten_env_reinterpret(bridge_addr); TEN_ASSERT(self && ten_go_ten_env_check_integrity(self), "Should not happen."); @@ -103,34 +176,36 @@ ten_go_error_t ten_go_ten_env_return_result(uintptr_t bridge_addr, TEN_ASSERT(cmd_result && ten_go_msg_check_integrity(cmd_result), "Should not happen."); - ten_go_error_t api_status; - ten_go_error_init_with_errno(&api_status, TEN_ERRNO_OK); + ten_go_error_t cgo_error; + ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); TEN_GO_TEN_ENV_IS_ALIVE_REGION_BEGIN( - self, { ten_go_error_set_errno(&api_status, TEN_ERRNO_TEN_IS_CLOSED); }); + self, { ten_go_error_set_errno(&cgo_error, TEN_ERRNO_TEN_IS_CLOSED); }); ten_error_t err; ten_error_init(&err); ten_env_notify_return_result_info_t *return_result_info = ten_env_notify_return_result_info_create( - ten_go_msg_move_c_msg(cmd_result), ten_go_msg_move_c_msg(cmd)); + ten_go_msg_move_c_msg(cmd_result), ten_go_msg_move_c_msg(cmd), + handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_return_result, return_result_info, false, &err)) { ten_env_notify_return_result_info_destroy(return_result_info); - ten_go_error_from_error(&api_status, &err); + ten_go_error_from_error(&cgo_error, &err); } ten_error_deinit(&err); TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); ten_is_close: - return api_status; + return cgo_error; } ten_go_error_t ten_go_ten_env_return_result_directly( - uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr) { + uintptr_t bridge_addr, uintptr_t cmd_result_bridge_addr, + ten_go_handle_t handler_id) { ten_go_ten_env_t *self = ten_go_ten_env_reinterpret(bridge_addr); TEN_ASSERT(self && ten_go_ten_env_check_integrity(self), "Should not happen."); @@ -139,68 +214,29 @@ ten_go_error_t ten_go_ten_env_return_result_directly( TEN_ASSERT(cmd_result && ten_go_msg_check_integrity(cmd_result), "Should not happen."); - ten_go_error_t api_status; - ten_go_error_init_with_errno(&api_status, TEN_ERRNO_OK); + ten_go_error_t cgo_error; + ten_go_error_init_with_errno(&cgo_error, TEN_ERRNO_OK); TEN_GO_TEN_ENV_IS_ALIVE_REGION_BEGIN( - self, { ten_go_error_set_errno(&api_status, TEN_ERRNO_TEN_IS_CLOSED); }); + self, { ten_go_error_set_errno(&cgo_error, TEN_ERRNO_TEN_IS_CLOSED); }); ten_error_t err; ten_error_init(&err); ten_env_notify_return_result_info_t *return_result_info = ten_env_notify_return_result_info_create( - ten_go_msg_move_c_msg(cmd_result), NULL); + ten_go_msg_move_c_msg(cmd_result), NULL, + handler_id <= 0 ? TEN_GO_NO_RESPONSE_HANDLER : handler_id); if (!ten_env_proxy_notify(self->c_ten_env_proxy, ten_env_proxy_notify_return_result, return_result_info, false, &err)) { ten_env_notify_return_result_info_destroy(return_result_info); - ten_go_error_from_error(&api_status, &err); + ten_go_error_from_error(&cgo_error, &err); } ten_error_deinit(&err); TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); ten_is_close: - return api_status; -} - -bool ten_go_ten_return_status_value(ten_go_ten_env_t *self, ten_go_msg_t *cmd, - TEN_STATUS_CODE status_code, - ten_value_t *status_value, - ten_go_error_t *api_status) { - TEN_ASSERT(self && ten_go_ten_env_check_integrity(self), - "Should not happen."); - TEN_ASSERT(cmd && ten_go_msg_check_integrity(cmd), "Should not happen."); - TEN_ASSERT(status_value && ten_value_check_integrity(status_value), - "Should not happen."); - TEN_ASSERT(api_status, "Should not happen."); - - bool result = true; - - ten_error_t err; - ten_error_init(&err); - - ten_shared_ptr_t *cmd_result = ten_cmd_result_create(status_code); - - TEN_GO_TEN_ENV_IS_ALIVE_REGION_BEGIN( - self, { ten_go_error_set_errno(api_status, TEN_ERRNO_TEN_IS_CLOSED); }); - - ten_env_notify_return_result_info_t *return_result_info = - ten_env_notify_return_result_info_create(cmd_result, - ten_go_msg_move_c_msg(cmd)); - if (!ten_env_proxy_notify(self->c_ten_env_proxy, - ten_env_proxy_notify_return_result, - return_result_info, false, &err)) { - result = false; - ten_env_notify_return_result_info_destroy(return_result_info); - ten_go_error_from_error(api_status, &err); - } - - TEN_GO_TEN_ENV_IS_ALIVE_REGION_END(self); - - ten_error_deinit(&err); - -ten_is_close: - return result; + return cgo_error; } diff --git a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c index 2bf146446b..ad3701d92f 100644 --- a/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c +++ b/core/src/ten_runtime/binding/python/native/ten_env/ten_env_return_result.c @@ -63,10 +63,11 @@ static void ten_env_proxy_notify_return_result(ten_env_t *ten_env, bool rc = false; if (info->c_target_cmd) { - rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, &err); + rc = ten_env_return_result(ten_env, info->c_cmd, info->c_target_cmd, NULL, + NULL, &err); TEN_ASSERT(rc, "Should not happen."); } else { - rc = ten_env_return_result_directly(ten_env, info->c_cmd, &err); + rc = ten_env_return_result_directly(ten_env, info->c_cmd, NULL, NULL, &err); TEN_ASSERT(rc, "Should not happen."); } diff --git a/core/src/ten_runtime/extension/extension.c b/core/src/ten_runtime/extension/extension.c index c587469a27..3e64747853 100644 --- a/core/src/ten_runtime/extension/extension.c +++ b/core/src/ten_runtime/extension/extension.c @@ -863,7 +863,7 @@ void ten_extension_on_cmd(ten_extension_t *self, ten_shared_ptr_t *msg) { // and return an 'OK' result to the previous stage. ten_shared_ptr_t *cmd_result = ten_cmd_result_create_from_cmd(TEN_STATUS_CODE_OK, msg); - ten_env_return_result(self->ten_env, cmd_result, msg, NULL); + ten_env_return_result(self->ten_env, cmd_result, msg, NULL, NULL, NULL); ten_shared_ptr_destroy(cmd_result); } } @@ -1041,7 +1041,8 @@ bool ten_extension_validate_msg_schema(ten_extension_t *self, ten_msg_set_property(cmd_result, "detail", ten_value_create_string(ten_error_errmsg(err)), NULL); - ten_env_return_result(self->ten_env, cmd_result, msg, NULL); + ten_env_return_result(self->ten_env, cmd_result, msg, NULL, NULL, + NULL); ten_shared_ptr_destroy(cmd_result); break; } diff --git a/core/src/ten_runtime/extension/msg_handling.c b/core/src/ten_runtime/extension/msg_handling.c index 9b6adb0ab5..0d5790da05 100644 --- a/core/src/ten_runtime/extension/msg_handling.c +++ b/core/src/ten_runtime/extension/msg_handling.c @@ -282,7 +282,8 @@ void ten_extension_handle_in_msg(ten_extension_t *self, ten_shared_ptr_t *msg) { // ExtensionB only needs to send the received cmdA to ExtensionC and // does not need to handle the result of cmdA. The TEN runtime will // help ExtensionB to return the result of cmdA to ExtensionA. - ten_env_return_result_directly(self->ten_env, actual_msg, NULL); + ten_env_return_result_directly(self->ten_env, actual_msg, NULL, NULL, + NULL); } } else { switch (ten_msg_get_type(msg)) { diff --git a/core/src/ten_runtime/ten_env/internal/return.c b/core/src/ten_runtime/ten_env/internal/return.c index 48a0240702..61d3412587 100644 --- a/core/src/ten_runtime/ten_env/internal/return.c +++ b/core/src/ten_runtime/ten_env/internal/return.c @@ -16,11 +16,11 @@ #include "ten_utils/lib/error.h" #include "ten_utils/macro/check.h" -static bool ten_env_return_result_internal(ten_env_t *self, - ten_shared_ptr_t *result_cmd, - const char *cmd_id, - const char *seq_id, - ten_error_t *err) { +static bool ten_env_return_result_internal( + ten_env_t *self, ten_shared_ptr_t *result_cmd, const char *cmd_id, + const char *seq_id, + ten_env_return_result_error_handler_func_t error_handler, + void *error_handler_data, ten_error_t *err) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.", self); @@ -50,6 +50,14 @@ static bool ten_env_return_result_internal(ten_env_t *self, "Invalid use of extension %p.", extension); bool result = ten_extension_handle_out_msg(extension, result_cmd, err); + if (result && error_handler) { + // If the method synchronously returns true, it means that the callback must + // be called. + // We temporarily assume that the message enqueue represents success; + // therefore, in this case, we set the error to NULL to indicate that the + // sending was successful. + error_handler(self, error_handler_data, NULL); + } if (err_new_created) { ten_error_destroy(err); @@ -60,9 +68,10 @@ static bool ten_env_return_result_internal(ten_env_t *self, // If the 'cmd' has already been a command in the backward path, a extension // could use this API to return the 'cmd' further. -bool ten_env_return_result_directly(ten_env_t *self, - ten_shared_ptr_t *result_cmd, - ten_error_t *err) { +bool ten_env_return_result_directly( + ten_env_t *self, ten_shared_ptr_t *result_cmd, + ten_env_return_result_error_handler_func_t error_handler, + void *error_handler_data, ten_error_t *err) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.", self); @@ -71,11 +80,14 @@ bool ten_env_return_result_directly(ten_env_t *self, TEN_ASSERT(ten_msg_get_type(result_cmd) == TEN_MSG_TYPE_CMD_RESULT, "The target cmd must be a cmd result."); - return ten_env_return_result_internal(self, result_cmd, NULL, NULL, err); + return ten_env_return_result_internal(self, result_cmd, NULL, NULL, + error_handler, error_handler_data, err); } -bool ten_env_return_result(ten_env_t *self, ten_shared_ptr_t *result_cmd, - ten_shared_ptr_t *target_cmd, ten_error_t *err) { +bool ten_env_return_result( + ten_env_t *self, ten_shared_ptr_t *result_cmd, ten_shared_ptr_t *target_cmd, + ten_env_return_result_error_handler_func_t error_handler, + void *error_handler_data, ten_error_t *err) { TEN_ASSERT(self, "Invalid argument."); TEN_ASSERT(ten_env_check_integrity(self, true), "Invalid use of ten_env %p.", self); @@ -86,7 +98,8 @@ bool ten_env_return_result(ten_env_t *self, ten_shared_ptr_t *result_cmd, TEN_ASSERT(ten_msg_get_type(target_cmd) != TEN_MSG_TYPE_CMD_RESULT, "The target cmd should not be a cmd result."); - return ten_env_return_result_internal( - self, result_cmd, ten_cmd_base_get_cmd_id(target_cmd), - ten_cmd_base_get_seq_id(target_cmd), err); + return ten_env_return_result_internal(self, result_cmd, + ten_cmd_base_get_cmd_id(target_cmd), + ten_cmd_base_get_seq_id(target_cmd), + error_handler, error_handler_data, err); } diff --git a/packages/core_extensions/default_extension_go/extension.go b/packages/core_extensions/default_extension_go/extension.go index 07b66307c3..4dc5255ccd 100644 --- a/packages/core_extensions/default_extension_go/extension.go +++ b/packages/core_extensions/default_extension_go/extension.go @@ -39,7 +39,7 @@ func (e *defaultExtension) OnCmd( tenEnv.LogDebug("OnCmd") cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } func init() { diff --git a/packages/core_extensions/default_extension_go/extension.go.tent b/packages/core_extensions/default_extension_go/extension.go.tent index 9fe3a73364..eb00e4cd64 100644 --- a/packages/core_extensions/default_extension_go/extension.go.tent +++ b/packages/core_extensions/default_extension_go/extension.go.tent @@ -43,7 +43,7 @@ func (e *{{class_name_prefix}}Extension) OnCmd( tenEnv.LogDebug("OnCmd") cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } func init() { diff --git a/packages/example_extensions/simple_http_server_go/main.go b/packages/example_extensions/simple_http_server_go/main.go index 9fab3ee621..e2a017e422 100644 --- a/packages/example_extensions/simple_http_server_go/main.go +++ b/packages/example_extensions/simple_http_server_go/main.go @@ -47,7 +47,7 @@ func (p *httpExtension) OnCmd( cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "This is default go extension.") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } func init() { diff --git a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go index 3c73c53a26..7b8f4418a6 100644 --- a/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/access_property_go/access_property_go_app/ten_packages/extension/extension_a/extension.go @@ -203,7 +203,7 @@ func (p *aExtension) OnCmd( cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "okok") - err = tenEnv.ReturnResult(cmdResult, cmd) + err = tenEnv.ReturnResult(cmdResult, cmd, nil) if err != nil { panic("ReturnResult failed") } diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go index 6357c8fb35..dd67047ec8 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_a/extension.go @@ -37,11 +37,11 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", detail.(*types.UserData).Name) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } }) diff --git a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go index 0e4c5139ef..3ea5ae0dec 100644 --- a/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/expired_ten_go/expired_ten_go_app/ten_packages/extension/extension_b/extension.go @@ -35,7 +35,7 @@ func (p *extensionB) OnCmd( data := types.UserData{Uid: 1, Name: "ten"} cs, _ := ten.NewCmdResult(ten.StatusCodeOk) cs.SetProperty("data", &data) - err := tenEnv.ReturnResult(cs, cmd) + err := tenEnv.ReturnResult(cs, cmd, nil) if err != nil { panic(err) } 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 ddbe80bf88..19d5dd31b1 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 @@ -125,14 +125,14 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) return } if detail != "this is extensionB." { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", "wrong detail") - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) return } @@ -140,13 +140,13 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) return } cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", password) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) }) }() } diff --git a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go index acad8f016c..3f844e9cb2 100644 --- a/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/frequently_cgo_call_go/frequently_cgo_call_go_app/ten_packages/extension/extension_b/extension.go @@ -86,17 +86,17 @@ func (p *extensionB) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } statusCmd.SetProperty("detail", "this is extensionB.") statusCmd.SetProperty("password", "password") - tenEnv.ReturnResult(statusCmd, cmd) + tenEnv.ReturnResult(statusCmd, cmd, nil) } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", "wrong cmd name") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } }() } diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go index 57a3936722..e4508c750d 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_a/extension.go @@ -35,7 +35,7 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) return } @@ -55,7 +55,7 @@ func (p *extensionA) OnCmd( statusCode, _ := cs.GetStatusCode() cmdResult, _ := ten.NewCmdResult(statusCode) cmdResult.SetPropertyString("detail", detail) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) }) }() } diff --git a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go index 212725954b..f7f8eeed46 100644 --- a/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/handle_error_go/handle_error_go_app/ten_packages/extension/extension_b/extension.go @@ -36,11 +36,11 @@ func (p *extensionB) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", res) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } } else { diff --git a/tests/ten_runtime/integration/go/no_dest_go/no_dest_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/no_dest_go/no_dest_go_app/ten_packages/extension/extension_a/extension.go index 064493abea..5d12b5cfea 100644 --- a/tests/ten_runtime/integration/go/no_dest_go/no_dest_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/no_dest_go/no_dest_go_app/ten_packages/extension/extension_a/extension.go @@ -102,7 +102,7 @@ func (p *aExtension) OnCmd( ) { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "okok") - err := tenEnv.ReturnResult(cmdResult, cmd) + err := tenEnv.ReturnResult(cmdResult, cmd, nil) if err != nil { panic("ReturnResult failed") } diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go index ccde47170a..da2fa8e7bb 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_a/extension.go @@ -45,7 +45,7 @@ func (p *aExtension) OnCmd( ) if cmdName == "start" { tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult, e error) { - r.ReturnResultDirectly(cs) + r.ReturnResultDirectly(cs, nil) }) } }() diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go index 8e48c2a6e6..ea2721f853 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_b/extension.go @@ -38,11 +38,11 @@ func (p *bExtension) OnCmd( ) if cmdName == "start" { tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult, e error) { - r.ReturnResultDirectly(cs) + r.ReturnResultDirectly(cs, nil) }) } else if cmdName == "stop" { tenEnv.SendCmd(cmd, func(r ten.TenEnv, cs ten.CmdResult, e error) { - r.ReturnResultDirectly(cs) + r.ReturnResultDirectly(cs, nil) close(p.stopChan) tenEnv.LogInfo("Stop command is processed.") @@ -50,7 +50,7 @@ func (p *bExtension) OnCmd( } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", "unknown cmd") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } }() } diff --git a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go index 3545a6c4cb..f6de29aff0 100644 --- a/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go +++ b/tests/ten_runtime/integration/go/prepare_to_stop_go/prepare_to_stop_go_app/ten_packages/extension/extension_c/extension.go @@ -40,13 +40,13 @@ func (p *cExtension) OnCmd( if cmdName == "start" { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "done") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } else if cmdName == "stop" { go func() { time.Sleep(time.Millisecond * 500) cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "done") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) tenEnv.LogInfo("Stop command is processed.") @@ -55,7 +55,7 @@ func (p *cExtension) OnCmd( } else { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", "unknown cmd") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } }() } diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go index 2a6b496d47..17336cbda6 100644 --- a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_a/extension.go @@ -36,14 +36,14 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } if detail != "this is extensionB." { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", "wrong detail") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } @@ -51,13 +51,13 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", password) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) }) }() } diff --git a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go index ad6e94ece8..b41ac5b666 100644 --- a/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/return_result_go/return_result_go_app/ten_packages/extension/extension_b/extension.go @@ -38,13 +38,13 @@ func (p *extensionB) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } statusCmd.SetProperty("detail", "this is extensionB.") statusCmd.SetProperty("password", "password") - tenEnv.ReturnResult(statusCmd, cmd) + tenEnv.ReturnResult(statusCmd, cmd, nil) } }() } diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go index e32a1b74d2..ca22cc25c1 100644 --- a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_a/extension.go @@ -37,13 +37,13 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) return } cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", detail.(*types.UserData).Name) - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) }) }() } diff --git a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go index 6f92de9c72..93782950c0 100644 --- a/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/return_value_go/return_value_go_app/ten_packages/extension/extension_b/extension.go @@ -36,7 +36,7 @@ func (p *extensionB) OnCmd( data := types.UserData{Uid: 1, Name: "ten"} cs, _ := ten.NewCmdResult(ten.StatusCodeOk) cs.SetProperty("data", &data) - err := tenEnv.ReturnResult(cs, cmd) + err := tenEnv.ReturnResult(cs, cmd, nil) if err != nil { panic(err) } diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go index c2b99d0d71..44b089cb00 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_a/extension.go @@ -60,7 +60,7 @@ func (p *aExtension) OnCmd( cmdResult2, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult2.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult2, cmd) + err = tenEnv.ReturnResult(cmdResult2, cmd, nil) if err != nil { panic("Should not happen.") } diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go index 69d0a45929..a96d62d026 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_b/extension.go @@ -63,7 +63,7 @@ func (p *bExtension) OnCmd( cmdResult2, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult2.SetPropertyString("detail", detail) - err = tenEnv.ReturnResult(cmdResult2, cmd) + err = tenEnv.ReturnResult(cmdResult2, cmd, nil) if err != nil { panic("Should not happen.") } diff --git a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go index b4e6a43a9e..ff6829a407 100644 --- a/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go +++ b/tests/ten_runtime/integration/go/three_extension_cmd_go/three_extension_cmd_go_app/ten_packages/extension/extension_c/extension.go @@ -53,7 +53,7 @@ func (p *cExtension) OnCmd( cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", string(res)) - err = tenEnv.ReturnResult(cmdResult, cmd) + err = tenEnv.ReturnResult(cmdResult, cmd, nil) if err != nil { panic("Should not happen.") } diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go index 2cf1ddc51c..a1a31ee1f8 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_a/extension.go @@ -49,13 +49,13 @@ func (p *extensionA) OnCmd( if err != nil { cmdResult, _ := ten.NewCmdResult(ten.StatusCodeError) cmdResult.SetPropertyString("detail", err.Error()) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) return } cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", detail) - r.ReturnResult(cmdResult, cmd) + r.ReturnResult(cmdResult, cmd, nil) }) }() } diff --git a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go index e68ed22414..926a184356 100644 --- a/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go +++ b/tests/ten_runtime/integration/go/transfer_pointer_go/transfer_pointer_go_app/ten_packages/extension/extension_b/extension.go @@ -70,7 +70,7 @@ func (p *extensionB) OnCmd( cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "ten") - tenEnv.ReturnResult(cmdResult, cmd) + tenEnv.ReturnResult(cmdResult, cmd, nil) } }() } diff --git a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go index 59a6ef903b..c3393269d6 100644 --- a/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go +++ b/tests/ten_runtime/integration/go/two_extension_one_group_cmd_go/two_extension_one_group_cmd_go_app/ten_packages/extension/addon_a/extension.go @@ -99,7 +99,7 @@ func (p *aExtension) OnCmd( cmdResult, _ := ten.NewCmdResult(ten.StatusCodeOk) cmdResult.SetPropertyString("detail", "world") - err = tenEnv.ReturnResult(cmdResult, cmd) + err = tenEnv.ReturnResult(cmdResult, cmd, nil) if err != nil { panic("aExtension ReturnResult failed") }