refactor: agentManager internal error message

Co-Authored-By: Agent

Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
yangxuguang-huawei
2026-05-27 15:49:40 +08:00
parent 09cd8823e7
commit b1f309754e
14 changed files with 276 additions and 119 deletions
@@ -22,6 +22,7 @@
#include <vector>
#include "ability_connect_callback.h"
#include "ability_business_error.h"
#include "ani.h"
#include "want.h"
@@ -179,7 +180,8 @@ public:
* @param env The ANI environment.
* @param error The error code.
*/
void RejectDuplicatedPendingCallbacks(ani_env *env, int32_t error);
void RejectDuplicatedPendingCallbacks(
ani_env *env, int32_t error, AbilityRuntime::AbilityInnerErrorMsg fallbackMessage);
/**
* Called when agent extension sends data.
@@ -15,6 +15,7 @@
#include "ets_agent_connection.h"
#include "ability_business_error.h"
#include "ability_connect_callback.h"
#include "agent_extension_connection_constants.h"
#include "ani_common_util.h"
@@ -166,6 +167,21 @@ void EtsAgentConnection::HandleOnAbilityConnectDone(
AppExecFwk::DetachAniEnv(etsVm_, isAttachThread);
return;
}
if (resultCode != static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_OK)) {
AppExecFwk::AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER,
reinterpret_cast<ani_object>(aniAsyncCallback_),
AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, resultCode, "",
AbilityRuntime::GetInnerErrorMsg(
AbilityRuntime::AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED)),
nullptr);
RejectDuplicatedPendingCallbacks(
env, resultCode, AbilityRuntime::AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED);
ReleaseObjectReference(env, aniAsyncCallback_);
aniAsyncCallback_ = nullptr;
AgentConnectionUtils::RemoveAgentConnection(connectionId_);
AppExecFwk::DetachAniEnv(etsVm_, isAttachThread);
return;
}
sptr<EtsAgentConnectorStubImpl> hostStub = GetServiceHostStub();
sptr<IRemoteObject> hostProxy = nullptr;
@@ -177,6 +193,18 @@ void EtsAgentConnection::HandleOnAbilityConnectDone(
connectionId_, hostProxy);
if (proxy == nullptr) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "CreateEtsAgentReceiverProxy failed");
int32_t errorCode = static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER);
AppExecFwk::AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER,
reinterpret_cast<ani_object>(aniAsyncCallback_),
AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, errorCode, "",
AbilityRuntime::GetInnerErrorMsg(
AbilityRuntime::AbilityInnerErrorMsg::OPERATION_FAILED)),
nullptr);
RejectDuplicatedPendingCallbacks(
env, errorCode, AbilityRuntime::AbilityInnerErrorMsg::OPERATION_FAILED);
ReleaseObjectReference(env, aniAsyncCallback_);
aniAsyncCallback_ = nullptr;
AgentConnectionUtils::RemoveAgentConnection(connectionId_);
AppExecFwk::DetachAniEnv(etsVm_, isAttachThread);
return;
}
@@ -214,14 +242,17 @@ void EtsAgentConnection::HandleOnAbilityDisconnectDone(const AppExecFwk::Element
return;
}
ani_object emptyProxy = nullptr;
AppExecFwk::AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER,
reinterpret_cast<ani_object>(aniAsyncCallback_),
AbilityRuntime::EtsErrorUtil::CreateError(env, static_cast<AbilityRuntime::AbilityErrorCode>(
AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER)), emptyProxy);
AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(
env, static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER), "",
AbilityRuntime::GetInnerErrorMsg(AbilityRuntime::AbilityInnerErrorMsg::AGENT_EXTENSION_CONNECTION_ENDED)),
nullptr);
RejectDuplicatedPendingCallbacks(env, static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER));
ReleaseObjectReference(aniAsyncCallback_);
RejectDuplicatedPendingCallbacks(env, static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER),
AbilityRuntime::AbilityInnerErrorMsg::AGENT_EXTENSION_CONNECTION_ENDED);
ReleaseObjectReference(env, aniAsyncCallback_);
aniAsyncCallback_ = nullptr;
CallObjectMethod(env, "onDisconnect", SIGNATURE_VOID);
AgentConnectionUtils::RemoveAgentConnection(connectionId_);
AppExecFwk::DetachAniEnv(etsVm_, isAttachThread);
@@ -368,7 +399,8 @@ void EtsAgentConnection::ResolveDuplicatedPendingCallbacks(ani_env *env, ani_obj
duplicatedPendingCallbacks_.clear();
}
void EtsAgentConnection::RejectDuplicatedPendingCallbacks(ani_env *env, int32_t error)
void EtsAgentConnection::RejectDuplicatedPendingCallbacks(
ani_env *env, int32_t error, AbilityRuntime::AbilityInnerErrorMsg fallbackMessage)
{
TAG_LOGD(AAFwkTag::SER_ROUTER, "RejectDuplicatedPendingCallbacks, size: %{public}zu",
duplicatedPendingCallbacks_.size());
@@ -376,10 +408,10 @@ void EtsAgentConnection::RejectDuplicatedPendingCallbacks(ani_env *env, int32_t
if (callback == nullptr) {
continue;
}
ani_object emptyProxy = nullptr;
AppExecFwk::AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER,
reinterpret_cast<ani_object>(callback),
AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(env, error), emptyProxy);
AbilityRuntime::EtsErrorUtil::CreateErrorByNativeErr(
env, error, "", AbilityRuntime::GetInnerErrorMsg(fallbackMessage)), nullptr);
ReleaseObjectReference(env, callback);
}
duplicatedPendingCallbacks_.clear();
@@ -322,7 +322,9 @@ void EtsAgentManager::GetAllAgentCards(ani_env *env, ani_object asyncCallback)
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "get all cards failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::READ_AGENT_CARDS)),
nullptr);
return;
}
if (cards.empty()) {
@@ -355,7 +357,9 @@ void EtsAgentManager::GetAgentCardsByBundleName(ani_env *env, ani_string aniBund
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "get cards by bundle failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::READ_AGENT_CARDS)),
nullptr);
return;
}
if (cards.empty()) {
@@ -396,7 +400,9 @@ void EtsAgentManager::GetAgentCardByAgentId(ani_env *env, ani_string aniBundleNa
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "get card by agentId failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::READ_AGENT_CARDS)),
nullptr);
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
@@ -422,7 +428,9 @@ void EtsAgentManager::RegisterAgentCard(ani_env *env, ani_object aniCard, ani_ob
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "register card failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::REGISTER_AGENT_CARD)),
nullptr);
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
@@ -448,7 +456,9 @@ void EtsAgentManager::UpdateAgentCard(ani_env *env, ani_object aniCard, ani_obje
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "update card failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::UPDATE_AGENT_CARD)),
nullptr);
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
@@ -483,7 +493,9 @@ void EtsAgentManager::DeleteAgentCard(ani_env *env, ani_string aniBundleName, an
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "delete card failed: %{public}d", ret);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(ret)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(static_cast<int32_t>(ret), AgentManagerErrorOperation::DELETE_AGENT_CARD)),
nullptr);
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
@@ -560,7 +572,10 @@ void EtsAgentManager::ConnectAgentExtensionAbility(ani_env *env, ani_object aniW
if (innerErrorCode != static_cast<int32_t>(AbilityErrorCode::ERROR_OK)) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "errcode: %{public}d.", innerErrorCode);
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, static_cast<int32_t>(innerErrorCode)), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrorCode)),
GetAgentManagerErrorMsg(
static_cast<int32_t>(innerErrorCode), AgentManagerErrorOperation::CONNECT_AGENT_EXTENSION)),
nullptr);
AgentConnectionUtils::RemoveAgentConnection(connectionId);
}
}
@@ -600,7 +615,9 @@ void EtsAgentManager::DisconnectAgentExtensionAbility(ani_env *env, ani_object a
TAG_LOGD(AAFwkTag::SER_ROUTER, "DisconnectAgentExtensionAbility innerErrorCode: %{public}d", innerErrCode);
if (innerErrCode != ERR_OK) {
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, innerErrCode), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrCode)),
GetAgentManagerErrorMsg(innerErrCode, AgentManagerErrorOperation::DISCONNECT_AGENT_EXTENSION)),
nullptr);
} else {
// On success, callback is handled by DisconnectAgentExtensionAbility via OnAbilityDisconnectDone
// Similar to how OnDisconnectUIServiceExtension always calls callback with ERROR_OK
@@ -704,7 +721,9 @@ void EtsAgentManager::DisconnectServiceExtensionAbility(
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, ret), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(ret, AgentManagerErrorOperation::DISCONNECT_SERVICE_EXTENSION)),
nullptr);
}
void EtsAgentManager::NotifyLowCodeAgentComplete(ani_env *env, ani_string aniAgentId, ani_object asyncCallback)
@@ -724,7 +743,9 @@ void EtsAgentManager::NotifyLowCodeAgentComplete(ani_env *env, ani_string aniAge
int32_t ret = AgentManagerClient::GetInstance().NotifyLowCodeAgentComplete(agentId);
if (ret != ERR_OK) {
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
EtsErrorUtil::CreateErrorByNativeErr(env, ret), nullptr);
EtsErrorUtil::CreateError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(ret)),
GetAgentManagerErrorMsg(ret, AgentManagerErrorOperation::COMPLETE_LOW_CODE_AGENT)),
nullptr);
return;
}
AsyncCallback(env, SIGNATURE_AGENT_ASYNC_CALLBACK_WRAPPER, asyncCallback,
@@ -15,6 +15,7 @@
#include "js_agent_connection.h"
#include "ability_business_error.h"
#include "agent_extension_connection_constants.h"
#include "hilog_tag_wrapper.h"
#include "js_agent_connector_stub_impl.h"
@@ -156,21 +157,42 @@ void JSAgentConnection::HandleOnAbilityConnectDone(const AppExecFwk::ElementName
const sptr<IRemoteObject> &remoteObject, int resultCode)
{
TAG_LOGI(AAFwkTag::SER_ROUTER, "HandleOnAbilityConnectDone, resultCode: %{public}d", resultCode);
if (napiAsyncTask_ != nullptr) {
TAG_LOGD(AAFwkTag::SER_ROUTER, "Creating JsAgentReceiverProxy");
sptr<JsAgentConnectorStubImpl> hostStub = GetServiceHostStub();
sptr<IRemoteObject> hostProxy = nullptr;
if (hostStub != nullptr) {
hostProxy = hostStub->AsObject();
}
napi_value proxy = AgentRuntime::JsAgentReceiverProxy::CreateJsAgentReceiverProxy(env_, remoteObject,
connectionId_, hostProxy);
SetProxyObject(proxy);
napiAsyncTask_->ResolveWithNoError(env_, proxy);
ResolveDuplicatedPendingTask(env_, proxy);
} else {
if (napiAsyncTask_ == nullptr) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "napiAsyncTask_ is null");
return;
}
if (resultCode != static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_OK)) {
napi_value error = CreateJsErrorByNativeErr(env_, resultCode, "",
AbilityRuntime::GetInnerErrorMsg(AbilityRuntime::AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED));
napiAsyncTask_->Reject(env_, error);
RejectDuplicatedPendingTask(env_, error);
napiAsyncTask_ = nullptr;
AgentConnectionUtils::RemoveAgentConnection(connectionId_);
return;
}
TAG_LOGD(AAFwkTag::SER_ROUTER, "Creating JsAgentReceiverProxy");
sptr<JsAgentConnectorStubImpl> hostStub = GetServiceHostStub();
sptr<IRemoteObject> hostProxy = nullptr;
if (hostStub != nullptr) {
hostProxy = hostStub->AsObject();
}
napi_value proxy = AgentRuntime::JsAgentReceiverProxy::CreateJsAgentReceiverProxy(env_, remoteObject,
connectionId_, hostProxy);
if (proxy == nullptr) {
napi_value error = CreateJsErrorByNativeErr(env_,
static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER), "",
AbilityRuntime::GetInnerErrorMsg(
AbilityRuntime::AbilityInnerErrorMsg::OPERATION_FAILED));
napiAsyncTask_->Reject(env_, error);
RejectDuplicatedPendingTask(env_, error);
napiAsyncTask_ = nullptr;
AgentConnectionUtils::RemoveAgentConnection(connectionId_);
return;
}
SetProxyObject(proxy);
napiAsyncTask_->ResolveWithNoError(env_, proxy);
ResolveDuplicatedPendingTask(env_, proxy);
napiAsyncTask_ = nullptr;
}
@@ -197,7 +219,9 @@ void JSAgentConnection::HandleOnAbilityDisconnectDone(const AppExecFwk::ElementN
{
TAG_LOGI(AAFwkTag::SER_ROUTER, "HandleOnAbilityDisconnectDone, resultCode: %{public}d", resultCode);
if (napiAsyncTask_ != nullptr) {
napi_value innerError = CreateJsError(env_, AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER);
napi_value innerError = CreateJsErrorByNativeErr(env_,
static_cast<int32_t>(AbilityRuntime::AbilityErrorCode::ERROR_CODE_INNER), "",
AbilityRuntime::GetInnerErrorMsg(AbilityRuntime::AbilityInnerErrorMsg::AGENT_EXTENSION_CONNECTION_ENDED));
napiAsyncTask_->Reject(env_, innerError);
RejectDuplicatedPendingTask(env_, innerError);
napiAsyncTask_ = nullptr;
@@ -18,7 +18,9 @@
#include <map>
#include <mutex>
#include "ability_business_error.h"
#include "ability_connection.h"
#include "ability_manager_errors.h"
#include "agent_connection_manager.h"
#include "agent_extension_connection_constants.h"
#include "agent_manager_client.h"
@@ -281,7 +283,8 @@ void DoConnectAgentExtensionAbility(napi_env env,
AbilityErrorCode errcode = AbilityRuntime::GetJsErrorCodeByNativeError(innerErrCode);
if (errcode != AbilityErrorCode::ERROR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "ConnectAgentExtensionAbility failed: %{public}d", errcode);
napi_value error = CreateJsError(env, errcode);
napi_value error = CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrCode)),
GetAgentManagerErrorMsg(innerErrCode, AgentManagerErrorOperation::CONNECT_AGENT_EXTENSION));
asyncTaskShared->Reject(env, error);
AgentConnectionUtils::RemoveAgentConnection(connectionId);
}
@@ -343,7 +346,8 @@ napi_value JsAgentManager::OnGetAllAgentCards(napi_env env, size_t argc, napi_va
napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::READ_AGENT_CARDS)));
return;
}
TAG_LOGI(AAFwkTag::SER_ROUTER, "cards.size: %{public}zu", cards->size());
@@ -380,7 +384,8 @@ napi_value JsAgentManager::OnGetAgentCardsByBundleName(napi_env env, size_t argc
napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::READ_AGENT_CARDS)));
return;
}
TAG_LOGI(AAFwkTag::SER_ROUTER, "cards.size: %{public}zu", cards->size());
@@ -424,7 +429,8 @@ napi_value JsAgentManager::OnGetAgentCardByAgentId(napi_env env, size_t argc, na
napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::READ_AGENT_CARDS)));
return;
}
task.ResolveWithNoError(env, CreateJsAgentCard(env, *card));
@@ -458,7 +464,8 @@ napi_value JsAgentManager::OnRegisterAgentCard(napi_env env, size_t argc, napi_v
NapiAsyncTask::CompleteCallback complete = [innerErrorCode](napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::REGISTER_AGENT_CARD)));
return;
}
task.ResolveWithNoError(env, CreateJsUndefined(env));
@@ -492,7 +499,8 @@ napi_value JsAgentManager::OnUpdateAgentCard(napi_env env, size_t argc, napi_val
NapiAsyncTask::CompleteCallback complete = [innerErrorCode](napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::UPDATE_AGENT_CARD)));
return;
}
task.ResolveWithNoError(env, CreateJsUndefined(env));
@@ -533,7 +541,8 @@ napi_value JsAgentManager::OnDeleteAgentCard(napi_env env, size_t argc, napi_val
NapiAsyncTask::CompleteCallback complete = [innerErrorCode](napi_env env, NapiAsyncTask &task, int32_t status) {
if (*innerErrorCode != ERR_OK) {
TAG_LOGE(AAFwkTag::SER_ROUTER, "error: %{public}d", *innerErrorCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrorCode)),
GetAgentManagerErrorMsg(*innerErrorCode, AgentManagerErrorOperation::DELETE_AGENT_CARD)));
return;
}
task.ResolveWithNoError(env, CreateJsUndefined(env));
@@ -742,7 +751,8 @@ napi_value JsAgentManager::OnDisconnectAgentExtensionAbility(napi_env env, size_
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
TAG_LOGE(AAFwkTag::SER_ROUTER, "Disconnect failed: %{public}d", *innerErrCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrCode)),
GetAgentManagerErrorMsg(*innerErrCode, AgentManagerErrorOperation::DISCONNECT_AGENT_EXTENSION)));
}
};
@@ -843,7 +853,8 @@ napi_value JsAgentManager::OnDisconnectServiceExtensionAbility(napi_env env, siz
task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
return;
}
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrCode)),
GetAgentManagerErrorMsg(*innerErrCode, AgentManagerErrorOperation::DISCONNECT_SERVICE_EXTENSION)));
};
napi_value result = nullptr;
@@ -873,7 +884,8 @@ napi_value JsAgentManager::OnNotifyLowCodeAgentComplete(napi_env env, size_t arg
if (*innerErrCode == ERR_OK) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(GetJsErrorCodeByNativeError(*innerErrCode)),
GetAgentManagerErrorMsg(*innerErrCode, AgentManagerErrorOperation::COMPLETE_LOW_CODE_AGENT)));
}
};
@@ -41,7 +41,8 @@ public:
static ani_object CreateError(ani_env *env, ani_int code, const std::string &msg);
static ani_object CreateInvalidParamError(ani_env *env, const std::string &message);
static ani_object CreateNoPermissionError(ani_env *env, const std::string &permission);
static ani_object CreateErrorByNativeErr(ani_env *env, int32_t err, const std::string &permission = "");
static ani_object CreateErrorByNativeErr(ani_env *env, int32_t err, const std::string &permission = "",
const std::string &innerErrMsg = "");
static ani_object WrapError(ani_env *env, const std::string &msg);
};
} // namespace AbilityRuntime
@@ -174,14 +174,15 @@ ani_object EtsErrorUtil::CreateNoPermissionError(ani_env *env, const std::string
env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED), GetNoPermissionErrorMsg(permission));
}
ani_object EtsErrorUtil::CreateErrorByNativeErr(ani_env *env, int32_t err, const std::string &permission)
ani_object EtsErrorUtil::CreateErrorByNativeErr(
ani_env *env, int32_t err, const std::string &permission, const std::string &innerErrMsg)
{
if (env == nullptr) {
TAG_LOGE(AAFwkTag::ANI, "null env");
return nullptr;
}
auto errCode = GetJsErrorCodeByNativeError(err);
auto errMsg = GetErrorMsgByNativeError(err, "", permission);
auto errMsg = GetErrorMsgByNativeError(err, innerErrMsg, permission);
return EtsErrorUtil::CreateError(env, static_cast<int32_t>(errCode), errMsg);
}
@@ -1059,7 +1059,7 @@ ani_object EtsAbilityContext::StartAbilityByCallWithAccount(
if (callData->remoteCallee == nullptr) {
EtsErrorUtil::ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_CALLER_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
return nullptr;
}
@@ -1074,7 +1074,7 @@ ani_object EtsAbilityContext::StartAbilityByCallWithAccount(
auto caller = EtsCallerComplex::CreateEtsCaller(env, releaseCallFunc, callData->remoteCallee, callerCallBack);
if (caller == nullptr) {
EtsErrorUtil::ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_CALLER_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
}
return caller;
}
@@ -2178,7 +2178,7 @@ void EtsAbilityContext::OnRestoreWindowStage(
localStorageRef_ == nullptr) {
TAG_LOGE(AAFwkTag::UI_EXT, "status : %{public}d", status);
EtsErrorUtil::ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_ANI_REFERENCE_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
return;
}
auto errCode = context->RestoreWindowStage(reinterpret_cast<void *>(localStorageRef_));
@@ -2525,7 +2525,7 @@ void EtsAbilityContext::OnRequestDialogService(ani_env *env, ani_object aniObj,
if (requestResult == nullptr) {
TAG_LOGW(AAFwkTag::CONTEXT, "null requestResult");
EtsErrorUtil::ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::REQUEST_DIALOG_RESULT_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
} else {
ani_object errorObj = EtsErrorUtil::CreateError(env, AbilityErrorCode::ERROR_OK);
AppExecFwk::AsyncCallback(env, reinterpret_cast<ani_object>(callbackRef), errorObj, requestResult);
@@ -2754,7 +2754,7 @@ void EtsAbilityContext::OnSetAbilityInstanceInfo(ani_env *env, ani_object aniObj
if ((status = env->GetVM(&etsVm)) != ANI_OK || etsVm == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status);
errorObj = EtsErrorUtil::CreateError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::GET_ANI_VM_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
AppExecFwk::AsyncCallback(env, callback, errorObj, nullptr);
return;
}
@@ -2763,7 +2763,7 @@ void EtsAbilityContext::OnSetAbilityInstanceInfo(ani_env *env, ani_object aniObj
if ((status = env->GlobalReference_Create(callback, &callbackRef)) != ANI_OK || callbackRef == nullptr) {
TAG_LOGE(AAFwkTag::CONTEXT, "status: %{public}d", status);
errorObj = EtsErrorUtil::CreateError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_ANI_REFERENCE_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
AppExecFwk::AsyncCallback(env, callback, errorObj, nullptr);
return;
}
@@ -2814,7 +2814,7 @@ void EtsAbilityContext::OnSetAbilityInstanceInfoInner(ani_env *env, std::string&
if (AniTask::AniSendEvent(task) != ANI_OK) {
TAG_LOGE(AAFwkTag::CONTEXT, "Failed to sendEvent");
errorObj = EtsErrorUtil::CreateError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
AppExecFwk::AsyncCallback(env, callback, errorObj, nullptr);
env->GlobalReference_Delete(callbackRef);
}
@@ -3047,7 +3047,7 @@ void EtsAbilityContext::OnSetOnNewWantSkipScenarios(ani_env *env, ani_object ani
TAG_LOGE(AAFwkTag::CONTEXT, "SetOnNewWantSkipScenarios failed, innerErrCode: %{public}d", innerErrCode);
AppExecFwk::AsyncCallback(env, callback, EtsErrorUtil::CreateError(
env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED)), nullptr);
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED)), nullptr);
return;
}
AppExecFwk::AsyncCallback(env, callback, EtsErrorUtil::CreateErrorByNativeErr(env, ERR_OK), nullptr);
@@ -182,12 +182,6 @@ constexpr const char* ERROR_MSG_DELAYED_PROCESS_EXIT_NOT_PENDING =
"Delayed process exit is not pending in the current process, and this API cannot be called.";
constexpr const char* ERROR_MSG_DELAYED_PROCESS_EXIT_HAS_OTHER_UIABILITY =
"The current process still has another UIAbility, and this API cannot be called.";
constexpr const char* ERROR_MSG_GET_ABILITY_SERVICE_FAILED =
"Internal error. The ability manager service is unavailable. Try again later.";
constexpr const char* ERROR_MSG_ABILITY_SERVICE_NOT_CONNECTED =
"Internal error. The ability manager service is not connected. Try again later.";
constexpr const char* ERROR_MSG_CREATE_MISSION_STACK_FAILED =
"Internal error. Failed to create the mission stack. Try again later.";
constexpr const char* ERROR_MSG_CREATE_ABILITY_RECORD_FAILED =
"Internal error. Failed to create the ability record. Check the Want parameters and try again.";
constexpr const char* ERROR_MSG_TERMINATE_LAUNCHER_DENIED =
@@ -197,16 +191,6 @@ constexpr const char* ERROR_MSG_CONNECTION_NOT_EXIST =
"connectServiceExtensionAbility.";
constexpr const char* ERROR_MSG_INVALID_CONNECTION_STATE =
"Internal error. The service connection state is invalid. Reconnect the service extension and try again.";
constexpr const char* ERROR_MSG_LOAD_ABILITY_TIMEOUT =
"Internal error. Loading the ability timed out. Try again later.";
constexpr const char* ERROR_MSG_CONNECTION_TIMEOUT =
"Internal error. Connecting the ability timed out. Try again later.";
constexpr const char* ERROR_MSG_GET_BUNDLE_MANAGER_SERVICE_FAILED =
"Internal error. The bundle manager service is unavailable. Try again later.";
constexpr const char* ERROR_MSG_REMOVE_MISSION_FAILED =
"Internal error. Failed to remove the mission. Try again later.";
constexpr const char* ERROR_MSG_GET_RECENT_MISSIONS_FAILED =
"Internal error. Failed to obtain recent missions. Try again later.";
constexpr const char* ERROR_MSG_REMOVE_STACK_LAUNCHER_DENIED =
"Internal error. The launcher mission stack cannot be removed.";
constexpr const char* ERROR_MSG_TERMINATE_SERVICE_IS_CONNECTED =
@@ -219,8 +203,6 @@ constexpr const char* ERROR_MSG_TERMINATE_ABILITY_RESULT_FAILED =
"Internal error. Failed to terminate the ability with result. Ensure the ability is active and try again.";
constexpr const char* ERROR_MSG_NO_FOUND_ABILITY_BY_CALLER =
"Internal error. The caller ability could not be found. Ensure the caller ability is still active.";
constexpr const char* ERROR_MSG_GET_BUNDLENAME_BY_UID_FAIL =
"Internal error. Failed to obtain the bundle name for the caller. Try again later.";
constexpr const char* ERROR_MSG_GET_BUNDLE_INFO_FAILED =
"Internal error. Failed to obtain bundle information. Check the target bundle and try again.";
constexpr const char* ERROR_MSG_RESOLVE_CALL_NO_PERMISSIONS =
@@ -230,8 +212,6 @@ constexpr const char* ERROR_MSG_RESOLVE_CALL_ABILITY_INNER_ERR =
"Check the Want parameters and target ability configuration.";
constexpr const char* ERROR_MSG_RESOLVE_CALL_ABILITY_VERSION_ERR =
"Internal error. The target callable ability version is incompatible.";
constexpr const char* ERROR_MSG_RELEASE_CALL_ABILITY_INNER_ERR =
"Internal error. Failed to release the caller connection. Try again later.";
constexpr const char* ERROR_MSG_INVALID_USERID_VALUE =
"Internal error. The user ID is invalid. Use a valid account ID and try again.";
constexpr const char* ERROR_MSG_ERR_AAFWK_PARCEL_FAIL =
@@ -240,33 +220,31 @@ constexpr const char* ERROR_MSG_ERR_REACH_UPPER_LIMIT =
"Internal error. The number of instances has reached the upper limit. Release unused instances and try again.";
constexpr const char* ERROR_MSG_ERR_AAFWK_INVALID_WINDOW_MODE =
"Internal error. The window mode is invalid. Use a supported window mode and try again.";
constexpr const char* ERROR_MSG_ERR_CONNECT_ERMS_FAILED =
"Internal error. Failed to connect to the ecological rule manager service. Try again later.";
constexpr const char* ERROR_MSG_ERR_NATIVE_IPC_PARCEL_FAILED =
"Internal error. Failed to parcel the IPC request. Check the input parameters and try again.";
constexpr const char* ERROR_MSG_ERR_NATIVE_ABILITY_NOT_FOUND =
"Internal error. The target ability could not be found. Check the Want parameters and ability configuration.";
constexpr const char* ERROR_MSG_ERR_NATIVE_ABILITY_STATE_CHECK_FAILED =
"Internal error. The ability state is invalid. Ensure the ability is active and try again.";
constexpr const char* ERROR_MSG_ERR_URI_LIST_OUT_OF_RANGE =
"Internal error. The URI list exceeds the supported size. Reduce the number of URIs and try again.";
constexpr const char* ERROR_MSG_CREATE_ANI_REFERENCE_FAILED =
"Internal error. Failed to create the ANI reference. Try again later.";
constexpr const char* ERROR_MSG_CREATE_CALLER_FAILED =
"Internal error. Failed to create the caller object. Try again later.";
constexpr const char* ERROR_MSG_GET_ANI_VM_FAILED =
"Internal error. Failed to obtain the ANI VM. Try again later.";
constexpr const char* ERROR_MSG_REQUEST_DIALOG_RESULT_FAILED =
"Internal error. Failed to create the dialog request result. Try again later.";
constexpr const char* ERROR_MSG_RESTORE_WINDOW_STAGE_FAILED =
"Internal error. Failed to restore the window stage. Check the local storage object and try again.";
constexpr const char* ERROR_MSG_SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED =
"Internal error. Failed to set onNewWant skip scenarios. Try again later.";
constexpr const char* ERROR_MSG_WRAP_ABILITY_RESULT_FAILED =
"Internal error. Failed to create the ability result. Check the returned Want and try again.";
constexpr const char* ERROR_MSG_SERVICE_UNAVAILABLE =
"Internal error. Service unavailable. Try again later.";
constexpr const char* ERROR_MSG_OPERATION_FAILED =
"Internal error. Operation failed. Try again later.";
constexpr const char* ERROR_MSG_TIMEOUT =
"Internal error. Operation timed out. Try again later.";
constexpr const char* ERROR_MSG_IPC_FAILED =
"Internal error. IPC failed. Try again later.";
constexpr const char* ERROR_MSG_CONNECT_AGENT_EXTENSION_FAILED =
"Internal error. Failed to connect to the agent extension ability. Verify the target and try again.";
constexpr const char* ERROR_MSG_AGENT_EXTENSION_CONNECTION_ENDED =
"Internal error. The agent extension connection ended before it was ready. Connect again.";
constexpr const char* ERROR_MSG_DISCONNECT_AGENT_EXTENSION_NOT_EXIST =
"Internal error. The agent extension connection does not exist. "
"Use an AgentProxy returned by connectAgentExtensionAbility.";
// follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework
constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220;
@@ -517,36 +495,36 @@ static std::unordered_map<int32_t, AbilityErrorCode> INNER_TO_JS_ERROR_CODE_MAP
};
static std::unordered_map<int32_t, const char*> INNER_ERROR_MSG_BY_NATIVE_CODE {
{GET_ABILITY_SERVICE_FAILED, ERROR_MSG_GET_ABILITY_SERVICE_FAILED},
{ABILITY_SERVICE_NOT_CONNECTED, ERROR_MSG_ABILITY_SERVICE_NOT_CONNECTED},
{CREATE_MISSION_STACK_FAILED, ERROR_MSG_CREATE_MISSION_STACK_FAILED},
{GET_ABILITY_SERVICE_FAILED, ERROR_MSG_SERVICE_UNAVAILABLE},
{ABILITY_SERVICE_NOT_CONNECTED, ERROR_MSG_SERVICE_UNAVAILABLE},
{CREATE_MISSION_STACK_FAILED, ERROR_MSG_OPERATION_FAILED},
{CREATE_ABILITY_RECORD_FAILED, ERROR_MSG_CREATE_ABILITY_RECORD_FAILED},
{TERMINATE_LAUNCHER_DENIED, ERROR_MSG_TERMINATE_LAUNCHER_DENIED},
{CONNECTION_NOT_EXIST, ERROR_MSG_CONNECTION_NOT_EXIST},
{INVALID_CONNECTION_STATE, ERROR_MSG_INVALID_CONNECTION_STATE},
{LOAD_ABILITY_TIMEOUT, ERROR_MSG_LOAD_ABILITY_TIMEOUT},
{CONNECTION_TIMEOUT, ERROR_MSG_CONNECTION_TIMEOUT},
{GET_BUNDLE_MANAGER_SERVICE_FAILED, ERROR_MSG_GET_BUNDLE_MANAGER_SERVICE_FAILED},
{REMOVE_MISSION_FAILED, ERROR_MSG_REMOVE_MISSION_FAILED},
{GET_RECENT_MISSIONS_FAILED, ERROR_MSG_GET_RECENT_MISSIONS_FAILED},
{LOAD_ABILITY_TIMEOUT, ERROR_MSG_TIMEOUT},
{CONNECTION_TIMEOUT, ERROR_MSG_TIMEOUT},
{GET_BUNDLE_MANAGER_SERVICE_FAILED, ERROR_MSG_SERVICE_UNAVAILABLE},
{REMOVE_MISSION_FAILED, ERROR_MSG_OPERATION_FAILED},
{GET_RECENT_MISSIONS_FAILED, ERROR_MSG_OPERATION_FAILED},
{REMOVE_STACK_LAUNCHER_DENIED, ERROR_MSG_REMOVE_STACK_LAUNCHER_DENIED},
{TERMINATE_SERVICE_IS_CONNECTED, ERROR_MSG_TERMINATE_SERVICE_IS_CONNECTED},
{START_SERVICE_ABILITY_ACTIVATING, ERROR_MSG_START_SERVICE_ABILITY_ACTIVATING},
{MOVE_MISSION_FAILED, ERROR_MSG_MOVE_MISSION_FAILED},
{TERMINATE_ABILITY_RESULT_FAILED, ERROR_MSG_TERMINATE_ABILITY_RESULT_FAILED},
{NO_FOUND_ABILITY_BY_CALLER, ERROR_MSG_NO_FOUND_ABILITY_BY_CALLER},
{GET_BUNDLENAME_BY_UID_FAIL, ERROR_MSG_GET_BUNDLENAME_BY_UID_FAIL},
{GET_BUNDLENAME_BY_UID_FAIL, ERROR_MSG_OPERATION_FAILED},
{GET_BUNDLE_INFO_FAILED, ERROR_MSG_GET_BUNDLE_INFO_FAILED},
{RESOLVE_CALL_NO_PERMISSIONS, ERROR_MSG_RESOLVE_CALL_NO_PERMISSIONS},
{RESOLVE_CALL_ABILITY_INNER_ERR, ERROR_MSG_RESOLVE_CALL_ABILITY_INNER_ERR},
{RESOLVE_CALL_ABILITY_VERSION_ERR, ERROR_MSG_RESOLVE_CALL_ABILITY_VERSION_ERR},
{RELEASE_CALL_ABILITY_INNER_ERR, ERROR_MSG_RELEASE_CALL_ABILITY_INNER_ERR},
{RELEASE_CALL_ABILITY_INNER_ERR, ERROR_MSG_OPERATION_FAILED},
{INVALID_USERID_VALUE, ERROR_MSG_INVALID_USERID_VALUE},
{ERR_AAFWK_PARCEL_FAIL, ERROR_MSG_ERR_AAFWK_PARCEL_FAIL},
{ERR_REACH_UPPER_LIMIT, ERROR_MSG_ERR_REACH_UPPER_LIMIT},
{ERR_AAFWK_INVALID_WINDOW_MODE, ERROR_MSG_ERR_AAFWK_INVALID_WINDOW_MODE},
{ERR_CONNECT_ERMS_FAILED, ERROR_MSG_ERR_CONNECT_ERMS_FAILED},
{ERR_NATIVE_IPC_PARCEL_FAILED, ERROR_MSG_ERR_NATIVE_IPC_PARCEL_FAILED},
{ERR_CONNECT_ERMS_FAILED, ERROR_MSG_SERVICE_UNAVAILABLE},
{ERR_NATIVE_IPC_PARCEL_FAILED, ERROR_MSG_IPC_FAILED},
{ERR_NATIVE_ABILITY_NOT_FOUND, ERROR_MSG_ERR_NATIVE_ABILITY_NOT_FOUND},
{ERR_NATIVE_ABILITY_STATE_CHECK_FAILED, ERROR_MSG_ERR_NATIVE_ABILITY_STATE_CHECK_FAILED},
{ERR_URI_LIST_OUT_OF_RANGE, ERROR_MSG_ERR_URI_LIST_OUT_OF_RANGE},
@@ -558,13 +536,13 @@ static std::unordered_map<int32_t, const char*> INNER_ERROR_MSG_BY_NATIVE_CODE {
};
static std::unordered_map<AbilityInnerErrorMsg, const char*> INNER_ERROR_MSG_BY_SCENE {
{AbilityInnerErrorMsg::CREATE_ANI_REFERENCE_FAILED, ERROR_MSG_CREATE_ANI_REFERENCE_FAILED},
{AbilityInnerErrorMsg::CREATE_CALLER_FAILED, ERROR_MSG_CREATE_CALLER_FAILED},
{AbilityInnerErrorMsg::GET_ANI_VM_FAILED, ERROR_MSG_GET_ANI_VM_FAILED},
{AbilityInnerErrorMsg::REQUEST_DIALOG_RESULT_FAILED, ERROR_MSG_REQUEST_DIALOG_RESULT_FAILED},
{AbilityInnerErrorMsg::SERVICE_UNAVAILABLE, ERROR_MSG_SERVICE_UNAVAILABLE},
{AbilityInnerErrorMsg::OPERATION_FAILED, ERROR_MSG_OPERATION_FAILED},
{AbilityInnerErrorMsg::RESTORE_WINDOW_STAGE_FAILED, ERROR_MSG_RESTORE_WINDOW_STAGE_FAILED},
{AbilityInnerErrorMsg::SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED, ERROR_MSG_SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED},
{AbilityInnerErrorMsg::WRAP_ABILITY_RESULT_FAILED, ERROR_MSG_WRAP_ABILITY_RESULT_FAILED},
{AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED, ERROR_MSG_CONNECT_AGENT_EXTENSION_FAILED},
{AbilityInnerErrorMsg::AGENT_EXTENSION_CONNECTION_ENDED, ERROR_MSG_AGENT_EXTENSION_CONNECTION_ENDED},
{AbilityInnerErrorMsg::DISCONNECT_AGENT_EXTENSION_NOT_EXIST, ERROR_MSG_DISCONNECT_AGENT_EXTENSION_NOT_EXIST},
};
}
@@ -602,6 +580,16 @@ std::string GetInnerErrorMsg(AbilityInnerErrorMsg innerErrMsg)
return GetErrorMsg(AbilityErrorCode::ERROR_CODE_INNER);
}
static AbilityInnerErrorMsg GetAgentManagerFailureMessage(AgentManagerErrorOperation operation)
{
switch (operation) {
case AgentManagerErrorOperation::CONNECT_AGENT_EXTENSION:
return AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED;
default:
return AbilityInnerErrorMsg::OPERATION_FAILED;
}
}
std::string GetErrorMsgByNativeError(int32_t errCode, const std::string& innerErrMsg, const std::string& permission)
{
auto jsErrCode = GetJsErrorCodeByNativeError(errCode);
@@ -616,10 +604,29 @@ std::string GetErrorMsgByNativeError(int32_t errCode, const std::string& innerEr
if (nativeMsg != INNER_ERROR_MSG_BY_NATIVE_CODE.end()) {
return nativeMsg->second;
}
if (errCode == static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER) && !innerErrMsg.empty()) {
if (!innerErrMsg.empty()) {
return innerErrMsg;
}
return GetErrorMsg(jsErrCode);
}
std::string GetAgentManagerErrorMsg(int32_t errCode, AgentManagerErrorOperation operation)
{
if (GetJsErrorCodeByNativeError(errCode) != AbilityErrorCode::ERROR_CODE_INNER) {
return GetErrorMsgByNativeError(errCode);
}
if (errCode == ERR_NULL_AGENT_MGR_PROXY) {
return GetInnerErrorMsg(AbilityInnerErrorMsg::SERVICE_UNAVAILABLE);
}
if (errCode == CONNECTION_NOT_EXIST) {
if (operation == AgentManagerErrorOperation::DISCONNECT_AGENT_EXTENSION) {
return GetInnerErrorMsg(AbilityInnerErrorMsg::DISCONNECT_AGENT_EXTENSION_NOT_EXIST);
}
if (operation == AgentManagerErrorOperation::COMPLETE_LOW_CODE_AGENT) {
return GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED);
}
}
return GetErrorMsgByNativeError(errCode, GetInnerErrorMsg(GetAgentManagerFailureMessage(operation)));
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -259,7 +259,7 @@ void StartAbilityByCallComplete(napi_env env, NapiAsyncTask& task, std::weak_ptr
TAG_LOGE(AAFwkTag::CONTEXT, "null callComplete params error %{public}s",
context == nullptr ? "context" : (calldata->remoteCallee == nullptr ? "remoteCallee" : "callerCallBack"));
task.Reject(env, CreateJsError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_CALLER_FAILED)));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED)));
TAG_LOGD(AAFwkTag::CONTEXT, "callComplete end");
return;
}
@@ -2162,7 +2162,7 @@ napi_value JsAbilityContext::OnRequestDialogService(napi_env env, NapiCallbackIn
if (requestResult == nullptr) {
TAG_LOGW(AAFwkTag::CONTEXT, "null requestResult");
asyncTask->Reject(env, CreateJsError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::REQUEST_DIALOG_RESULT_FAILED)));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED)));
} else {
asyncTask->Resolve(env, requestResult);
}
@@ -3516,7 +3516,7 @@ napi_value JsAbilityContext::OnSetOnNewWantSkipScenarios(napi_env env, NapiCallb
task.Resolve(env, CreateJsUndefined(env));
} else {
task.Reject(env, CreateJsError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER),
GetInnerErrorMsg(AbilityInnerErrorMsg::SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED)));
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED)));
}
};
+7 -1
View File
@@ -105,10 +105,16 @@ napi_value CreateNoPermissionError(napi_env env, const std::string& permission)
}
napi_value CreateJsErrorByNativeErr(napi_env env, int32_t err, const std::string& permission)
{
return CreateJsErrorByNativeErr(env, err, permission, "");
}
napi_value CreateJsErrorByNativeErr(
napi_env env, int32_t err, const std::string& permission, const std::string& innerErrMsg)
{
HandleEscape handleEscape(env);
auto errCode = GetJsErrorCodeByNativeError(err);
auto errMsg = GetErrorMsgByNativeError(err, "", permission);
auto errMsg = GetErrorMsgByNativeError(err, innerErrMsg, permission);
return handleEscape.Escape(CreateJsError(env, static_cast<int32_t>(errCode), errMsg));
}
} // namespace AbilityRuntime
@@ -36,6 +36,8 @@ napi_value CreateJsError(napi_env env, const AbilityErrorCode& err);
napi_value CreateInvalidParamJsError(napi_env env, const std::string &message);
napi_value CreateNoPermissionError(napi_env env, const std::string& permission);
napi_value CreateJsErrorByNativeErr(napi_env env, int32_t err, const std::string& permission = "");
napi_value CreateJsErrorByNativeErr(
napi_env env, int32_t err, const std::string& permission, const std::string& innerErrMsg);
} // namespace AbilityRuntime
} // namespace OHOS
@@ -338,13 +338,24 @@ enum class AbilityErrorCode {
};
enum class AbilityInnerErrorMsg {
CREATE_ANI_REFERENCE_FAILED,
CREATE_CALLER_FAILED,
GET_ANI_VM_FAILED,
REQUEST_DIALOG_RESULT_FAILED,
SERVICE_UNAVAILABLE,
OPERATION_FAILED,
RESTORE_WINDOW_STAGE_FAILED,
SET_ON_NEW_WANT_SKIP_SCENARIOS_FAILED,
WRAP_ABILITY_RESULT_FAILED,
CONNECT_AGENT_EXTENSION_FAILED,
AGENT_EXTENSION_CONNECTION_ENDED,
DISCONNECT_AGENT_EXTENSION_NOT_EXIST,
};
enum class AgentManagerErrorOperation {
READ_AGENT_CARDS,
REGISTER_AGENT_CARD,
UPDATE_AGENT_CARD,
DELETE_AGENT_CARD,
CONNECT_AGENT_EXTENSION,
DISCONNECT_AGENT_EXTENSION,
DISCONNECT_SERVICE_EXTENSION,
COMPLETE_LOW_CODE_AGENT,
};
std::string GetErrorMsg(const AbilityErrorCode& errCode);
@@ -353,6 +364,7 @@ AbilityErrorCode GetJsErrorCodeByNativeError(int32_t errCode);
std::string GetInnerErrorMsg(AbilityInnerErrorMsg innerErrMsg);
std::string GetErrorMsgByNativeError(int32_t errCode, const std::string& innerErrMsg = "",
const std::string& permission = "");
std::string GetAgentManagerErrorMsg(int32_t errCode, AgentManagerErrorOperation operation);
} // namespace AbilityRuntime
} // namespace OHOS
#endif
@@ -126,7 +126,15 @@ HWTEST_F(AbilityBusinessErrorTest, GetErrorMsgByNativeError_0100, TestSize.Level
const std::string innerErrMsg = "Internal error. Failed to start the ability. Try again later.";
EXPECT_EQ(GetErrorMsgByNativeError(0), "OK.");
EXPECT_EQ(GetErrorMsgByNativeError(-1000), "Internal error.");
EXPECT_EQ(GetErrorMsgByNativeError(-1000, innerErrMsg), "Internal error.");
EXPECT_EQ(GetErrorMsgByNativeError(-1000, innerErrMsg), innerErrMsg);
EXPECT_EQ(GetErrorMsgByNativeError(AAFwk::GET_ABILITY_SERVICE_FAILED),
"Internal error. Service unavailable. Try again later.");
EXPECT_EQ(GetErrorMsgByNativeError(AAFwk::CREATE_MISSION_STACK_FAILED),
"Internal error. Operation failed. Try again later.");
EXPECT_EQ(GetErrorMsgByNativeError(AAFwk::LOAD_ABILITY_TIMEOUT),
"Internal error. Operation timed out. Try again later.");
EXPECT_EQ(GetErrorMsgByNativeError(AAFwk::ERR_NATIVE_IPC_PARCEL_FAILED),
"Internal error. IPC failed. Try again later.");
EXPECT_EQ(GetErrorMsgByNativeError(AAFwk::CONNECTION_NOT_EXIST, innerErrMsg),
"Internal error. The service connection does not exist. Use a connection ID returned by "
"connectServiceExtensionAbility.");
@@ -146,10 +154,39 @@ HWTEST_F(AbilityBusinessErrorTest, GetErrorMsgByNativeError_0100, TestSize.Level
*/
HWTEST_F(AbilityBusinessErrorTest, GetInnerErrorMsg_0100, TestSize.Level2)
{
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::CREATE_CALLER_FAILED),
"Internal error. Failed to create the caller object. Try again later.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::SERVICE_UNAVAILABLE),
"Internal error. Service unavailable. Try again later.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED),
"Internal error. Operation failed. Try again later.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::RESTORE_WINDOW_STAGE_FAILED),
"Internal error. Failed to restore the window stage. Check the local storage object and try again.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::CONNECT_AGENT_EXTENSION_FAILED),
"Internal error. Failed to connect to the agent extension ability. Verify the target and try again.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::AGENT_EXTENSION_CONNECTION_ENDED),
"Internal error. The agent extension connection ended before it was ready. Connect again.");
EXPECT_EQ(GetInnerErrorMsg(AbilityInnerErrorMsg::DISCONNECT_AGENT_EXTENSION_NOT_EXIST),
"Internal error. The agent extension connection does not exist. "
"Use an AgentProxy returned by connectAgentExtensionAbility.");
}
/**
* @tc.name: GetAgentManagerErrorMsg_0100
* @tc.desc: Verify agentManager operation policy selects centralized messages without replacing mapped errors.
* @tc.type: FUNC
*/
HWTEST_F(AbilityBusinessErrorTest, GetAgentManagerErrorMsg_0100, TestSize.Level2)
{
EXPECT_EQ(GetAgentManagerErrorMsg(-1000, AgentManagerErrorOperation::READ_AGENT_CARDS),
GetInnerErrorMsg(AbilityInnerErrorMsg::OPERATION_FAILED));
EXPECT_EQ(GetAgentManagerErrorMsg(AAFwk::ERR_NULL_AGENT_MGR_PROXY,
AgentManagerErrorOperation::READ_AGENT_CARDS),
GetInnerErrorMsg(AbilityInnerErrorMsg::SERVICE_UNAVAILABLE));
EXPECT_EQ(GetAgentManagerErrorMsg(AAFwk::CONNECTION_NOT_EXIST,
AgentManagerErrorOperation::DISCONNECT_AGENT_EXTENSION),
GetInnerErrorMsg(AbilityInnerErrorMsg::DISCONNECT_AGENT_EXTENSION_NOT_EXIST));
EXPECT_EQ(GetAgentManagerErrorMsg(AAFwk::ERR_MAX_AGENT_CONNECTIONS_REACHED,
AgentManagerErrorOperation::CONNECT_AGENT_EXTENSION),
GetErrorMsg(AbilityErrorCode::ERROR_CODE_MAX_CONNECTIONS_REACHED));
}
} // namespace AAFwk
} // namespace OHOS