diff --git a/interfaces/kits/napi/account_iam/src/napi_account_iam_inputer_manager.cpp b/interfaces/kits/napi/account_iam/src/napi_account_iam_inputer_manager.cpp index 28df60ff51ce2cd2427220c6ffb61d189bb4d4b3..8a5640e291bfba9e7532c77721a6096367e72219 100644 --- a/interfaces/kits/napi/account_iam/src/napi_account_iam_inputer_manager.cpp +++ b/interfaces/kits/napi/account_iam/src/napi_account_iam_inputer_manager.cpp @@ -54,13 +54,13 @@ static bool ParseContextForRegisterInputer( napi_value argv[ARG_SIZE_TWO] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARG_SIZE_TWO) { - std::string errMsg = "The number of parameter must be two"; + std::string errMsg = "Parameter error. The number of parameters should be at least 2"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } if (!GetIntProperty(env, argv[PARAM_ZERO], authType)) { - std::string errMsg = "The type of parameter authType must be number"; + std::string errMsg = "Parameter error. The type of \"authType\" must be AuthType"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; @@ -68,7 +68,7 @@ static bool ParseContextForRegisterInputer( bool hasProp = false; napi_has_named_property(env, argv[PARAM_ONE], "onGetData", &hasProp); if (!hasProp) { - std::string errMsg = "The onGetData function should be contained in the inputer, but not found"; + std::string errMsg = "Parameter error. The type of \"inputer\" must be IInputer"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; @@ -76,7 +76,7 @@ static bool ParseContextForRegisterInputer( napi_value onGetData = nullptr; napi_get_named_property(env, argv[PARAM_ONE], "onGetData", &onGetData); if (!GetCallbackProperty(env, onGetData, callback, 1)) { - std::string errMsg = "The onGetData is not a function"; + std::string errMsg = "Parameter error. The type of \"inputer\" must be IInputer"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; @@ -107,14 +107,14 @@ napi_value NapiAccountIAMInputerManager::UnregisterInputer(napi_env env, napi_ca napi_value argv[ARG_SIZE_ONE] = {nullptr}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARG_SIZE_ONE) { - std::string errMsg = "The number of parameter must be one"; + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } int32_t authType = -1; if (!GetIntProperty(env, argv[PARAM_ZERO], authType)) { - std::string errMsg = "The type of parameter authType must be number"; + std::string errMsg = "Parameter error. The type of \"authType\" must be AuthType"; ACCOUNT_LOGE("%{public}s", errMsg.c_str()); AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; diff --git a/interfaces/kits/napi/account_iam/src/napi_account_iam_pin_auth.cpp b/interfaces/kits/napi/account_iam/src/napi_account_iam_pin_auth.cpp index 8aa8878f709e7cf2488b2d06a45f5320f8ffcb91..7c00ea3fde8c3b8c5f71234a3177d4d210669cc4 100644 --- a/interfaces/kits/napi/account_iam/src/napi_account_iam_pin_auth.cpp +++ b/interfaces/kits/napi/account_iam/src/napi_account_iam_pin_auth.cpp @@ -55,7 +55,7 @@ static bool ParseContextForRegisterInputer(napi_env env, napi_callback_info info napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARG_SIZE_ONE) { ACCOUNT_LOGE("expect at least one parameter, but got %zu", argc); - std::string errMsg = "The arg number must be at least " + std::to_string(ARG_SIZE_ONE) + " characters"; + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } @@ -68,7 +68,7 @@ static bool ParseContextForRegisterInputer(napi_env env, napi_callback_info info onGetData = argv[PARAM_ZERO]; } else { ACCOUNT_LOGE("inputer param type error"); - std::string errMsg = "The type of arg 1 must be function or object"; + std::string errMsg = "Parameter error. The type of \"inputer\" must be function or object"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } diff --git a/interfaces/kits/napi/account_iam/src/napi_account_iam_user_auth.cpp b/interfaces/kits/napi/account_iam/src/napi_account_iam_user_auth.cpp index 1b3a836d976c4bd1aff3d42fd0537b5acd3a0290..507a388910808432ba5c36a67c2945848e770f1c 100644 --- a/interfaces/kits/napi/account_iam/src/napi_account_iam_user_auth.cpp +++ b/interfaces/kits/napi/account_iam/src/napi_account_iam_user_auth.cpp @@ -71,14 +71,14 @@ napi_value NapiAccountIAMUserAuth::GetAvailableStatus(napi_env env, napi_callbac NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); if (argc != ARG_SIZE_TWO) { ACCOUNT_LOGE("expect 2 parameters, but got %{public}zu", argc); - std::string errMsg = "The arg number must be 2 characters"; + std::string errMsg = "Parameter error. The number of parameters should be at least 2"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } napi_valuetype valType = napi_undefined; napi_typeof(env, argv[PARAM_ZERO], &valType); if (valType != napi_number) { - std::string errMsg = "The type of arg 1 must be number"; + std::string errMsg = "Parameter error. The type of \"authType\" must be number"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } @@ -86,7 +86,7 @@ napi_value NapiAccountIAMUserAuth::GetAvailableStatus(napi_env env, napi_callbac napi_get_value_int32(env, argv[PARAM_ZERO], &authType); napi_typeof(env, argv[PARAM_ONE], &valType); if (valType != napi_number) { - std::string errMsg = "The type of arg 2 must be number"; + std::string errMsg = "Parameter error. The type of \"authTrustLevel\" must be number"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } @@ -117,7 +117,7 @@ static napi_status ParseContextForGetSetProperty( NAPI_CALL_BASE(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), napi_generic_failure); if (argc < ARG_SIZE_ONE) { ACCOUNT_LOGE("expect at least 1 parameter, but got zero"); - std::string errMsg = "The arg number must be at least 1 character"; + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_generic_failure; } @@ -134,14 +134,14 @@ static napi_status ParseContextForGetSetProperty( if (isGet) { if (ParseGetPropRequest(env, argv[PARAM_ZERO], reinterpret_cast(context)->request) != napi_ok) { - std::string errMsg = "Arg 1 must be a valid GetPropertyRequest"; + std::string errMsg = "Parameter error. The type of \"request\" must be GetPropertyRequest"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_generic_failure; } } else { if (ParseSetPropRequest(env, argv[PARAM_ZERO], reinterpret_cast(context)->request) != napi_ok) { - std::string errMsg = "Arg 1 must be a valid SetPropertyRequest"; + std::string errMsg = "Parameter error. The type of \"request\" must be SetPropertyRequest"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_generic_failure; } @@ -220,19 +220,27 @@ static napi_status ParseContextForAuth(napi_env env, napi_value *argv, size_t ar size_t index = 0; if (ParseUint8TypedArrayToVector(env, argv[index++], context.challenge) != napi_ok) { ACCOUNT_LOGE("fail to parse challenge"); + std::string errMsg = "Parameter error. The type of \"challenge\" must be Uint8Array"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } if (!GetIntProperty(env, argv[index++], context.authType)) { ACCOUNT_LOGE("fail to parse authType"); + std::string errMsg = "Parameter error. The type of \"authType\" must be AuthType"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } if (!GetIntProperty(env, argv[index++], context.trustLevel)) { ACCOUNT_LOGE("fail to parse trustLevel"); + std::string errMsg = "Parameter error. The type of \"authTrustLevel\" must be AuthTrustLevel";; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } std::shared_ptr jsCallback = std::make_shared(env); if (ParseIAMCallback(env, argv[index++], jsCallback) != napi_ok) { ACCOUNT_LOGE("fail to parse callback"); + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } context.callback = std::make_shared(env, jsCallback); @@ -243,10 +251,14 @@ static napi_status ParseContextForAuthUser(napi_env env, napi_value *argv, size_ { if (argc != ARG_SIZE_FIVE) { ACCOUNT_LOGE("the number of parameter is incorrect, expect 5, but got %{public}zu", argc); + std::string errMsg = "Parameter error. The number of parameters should be at least 5"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } if (!GetIntProperty(env, argv[0], context.userId)) { ACCOUNT_LOGE("Get userId failed"); + std::string errMsg = "Parameter error. The type of \"userId\" must be number"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return napi_invalid_arg; } return ParseContextForAuth(env, &argv[1], ARG_SIZE_FOUR, context); @@ -257,9 +269,14 @@ napi_value NapiAccountIAMUserAuth::Auth(napi_env env, napi_callback_info info) size_t argc = ARG_SIZE_FOUR; napi_value argv[ARG_SIZE_FOUR] = {0}; napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (argc != ARG_SIZE_FOUR) { + ACCOUNT_LOGE("the number of parameter is incorrect, expect 4, but got %{public}zu", argc); + std::string errMsg = "Parameter error. The number of parameters should be at least 4"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); + return nullptr; + } AuthContext context; if (ParseContextForAuth(env, argv, argc, context) == napi_invalid_arg) { - AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR); return nullptr; } uint64_t contextId = AccountIAMClient::GetInstance().Auth(context.challenge, @@ -274,7 +291,6 @@ napi_value NapiAccountIAMUserAuth::AuthUser(napi_env env, napi_callback_info inf napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); AuthContext context; if (ParseContextForAuthUser(env, argv, argc, context) == napi_invalid_arg) { - AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR); return nullptr; } uint64_t contextId = AccountIAMClient::GetInstance().AuthUser(context.userId, context.challenge, @@ -289,14 +305,14 @@ napi_value NapiAccountIAMUserAuth::CancelAuth(napi_env env, napi_callback_info i napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); if (argc != ARG_SIZE_ONE) { ACCOUNT_LOGE("failed to parse parameters, expect at least one parameter, but got %zu", argc); - std::string errMsg = "The arg number must be at least " + std::to_string(ARG_SIZE_ONE) + " characters"; + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } uint64_t contextId = 0; if (ParseUint8TypedArrayToUint64(env, argv[0], contextId) != napi_ok) { ACCOUNT_LOGE("failed to parse contextId"); - std::string errMsg = "The type of arg 1 must be number"; + std::string errMsg = "Parameter error. The type of \"contextID\" must be Uint8Array"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } diff --git a/interfaces/kits/napi/domain_account/src/napi_domain_account_manager.cpp b/interfaces/kits/napi/domain_account/src/napi_domain_account_manager.cpp index 28d0fdb1e70084953163bdd8ad8197056307e6db..75b0ac18b321e4ab5912c55d199b81f79ab1bce6 100644 --- a/interfaces/kits/napi/domain_account/src/napi_domain_account_manager.cpp +++ b/interfaces/kits/napi/domain_account/src/napi_domain_account_manager.cpp @@ -950,7 +950,8 @@ napi_value NapiDomainAccountManager::RegisterPlugin(napi_env env, napi_callback_ { JsDomainPlugin jsPlugin; if (!ParseContextForRegisterPlugin(env, cbInfo, jsPlugin)) { - AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, true); + std::string errMsg = "Parameter error. The type of \"plugin\" must be DomainPlugin"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return nullptr; } auto plugin = std::make_shared(env, jsPlugin); @@ -1002,19 +1003,27 @@ static bool ParseContextForAuth(napi_env env, napi_callback_info cbInfo, JsDomai NAPI_CALL_BASE(env, napi_get_cb_info(env, cbInfo, &argc, argv, nullptr, nullptr), false); if (argc != ARG_SIZE_THREE) { ACCOUNT_LOGE("the number of parameter must be one, but got %{public}zu", argc); + std::string errMsg = "Parameter error. The number of parameters should be at least 3"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } int index = 0; if (!ParseDomainAccountInfo(env, argv[index++], authContext.domainAccountInfo)) { ACCOUNT_LOGE("get domainInfo failed"); + std::string errMsg = "Parameter error. The type of \"domainAccountInfo\" must be DomainAccountInfo"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } if (ParseUint8TypedArrayToVector(env, argv[index++], authContext.authData) != napi_ok) { ACCOUNT_LOGE("get credential failed"); + std::string errMsg = "Parameter error. The type of \"credential\" must be Uint8Array"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } if (!GetNamedJsFunction(env, argv[index++], "onResult", authContext.callbackRef)) { ACCOUNT_LOGE("get callback failed"); + std::string errMsg = "Parameter error. The type of \"callback\" must be IUserAuthCallback"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); return false; } return true; @@ -1029,7 +1038,6 @@ napi_value NapiDomainAccountManager::Auth(napi_env env, napi_callback_info cbInf { auto authContext = std::make_unique(env); if (!ParseContextForAuth(env, cbInfo, *authContext)) { - AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, true); return nullptr; } napi_value resource = nullptr; diff --git a/interfaces/kits/napi/osaccount/src/napi_os_account.cpp b/interfaces/kits/napi/osaccount/src/napi_os_account.cpp index b95bf8f6fdbc7cd1b2e7ef07b94eada64a99239f..41a72eaa7993ac73cf474773039bef5823738ac5 100644 --- a/interfaces/kits/napi/osaccount/src/napi_os_account.cpp +++ b/interfaces/kits/napi/osaccount/src/napi_os_account.cpp @@ -877,29 +877,35 @@ napi_value GetOsAccountLocalIdForUid(napi_env env, napi_callback_info cbInfo) return GetOsAccountLocalIdFromUidInner(env, cbInfo, true); } -static ErrCode ParseUidFromCbInfo(napi_env env, napi_callback_info cbInfo, int32_t &uid) +static bool ParseUidFromCbInfo(napi_env env, napi_callback_info cbInfo, int32_t &uid) { size_t argc = ARGS_SIZE_ONE; napi_value argv[ARGS_SIZE_ONE] = {0}; napi_get_cb_info(env, cbInfo, &argc, argv, nullptr, nullptr); - if ((argc == 0) || (!GetIntProperty(env, argv[0], uid))) { - ACCOUNT_LOGE("failed to parse uid"); - return ERR_JS_PARAMETER_ERROR; + if (argc == 0) { + ACCOUNT_LOGE("The number of parameters should be at least 1."); + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); + return false; + } + if (!GetIntProperty(env, argv[0], uid)) { + ACCOUNT_LOGE("Get uid failed."); + std::string errMsg = "Parameter error. The type of \"uid\" must be number"; + AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, true); + return false; } - return ERR_OK; + return true; } napi_value GetOsAccountLocalIdForUidSync(napi_env env, napi_callback_info cbInfo) { napi_value napiValue = nullptr; int32_t uid = 0; - ErrCode errCode = ParseUidFromCbInfo(env, cbInfo, uid); - if (errCode != ERR_OK) { - AccountNapiThrow(env, errCode); + if (!ParseUidFromCbInfo(env, cbInfo, uid)) { return napiValue; } int32_t localId = 0; - errCode = OsAccountManager::GetOsAccountLocalIdFromUid(uid, localId); + ErrCode errCode = OsAccountManager::GetOsAccountLocalIdFromUid(uid, localId); if (errCode != ERR_OK) { AccountNapiThrow(env, errCode); return napiValue; @@ -943,13 +949,11 @@ napi_value GetBundleIdForUidSync(napi_env env, napi_callback_info cbInfo) { napi_value retValue = nullptr; int32_t uid = 0; - ErrCode errCode = ParseUidFromCbInfo(env, cbInfo, uid); - if (errCode != ERR_OK) { - AccountNapiThrow(env, errCode); + if (!ParseUidFromCbInfo(env, cbInfo, uid)) { return retValue; } int32_t bundleId = 0; - errCode = OsAccountManager::GetBundleIdFromUid(uid, bundleId); + ErrCode errCode = OsAccountManager::GetBundleIdFromUid(uid, bundleId); if (errCode != ERR_OK) { AccountNapiThrow(env, errCode); return retValue; diff --git a/interfaces/kits/napi/osaccount/src/napi_os_account_common.cpp b/interfaces/kits/napi/osaccount/src/napi_os_account_common.cpp index 05b55e868c0c00fabf6b8c93566e72f79e6ed3dc..b3f278b08f6684755faed26d6d36b82c91e3d50c 100644 --- a/interfaces/kits/napi/osaccount/src/napi_os_account_common.cpp +++ b/interfaces/kits/napi/osaccount/src/napi_os_account_common.cpp @@ -82,7 +82,7 @@ static bool ParseOneParaContext(napi_env env, napi_callback_info cbInfo, CommonA if (argc == ARGS_SIZE_ONE) { if (!GetCallbackProperty(env, argv[argc - 1], asyncContext->callbackRef, 1)) { ACCOUNT_LOGE("Get callbackRef failed"); - std::string errMsg = "The type of arg " + std::to_string(argc) + " must be function"; + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -876,7 +876,7 @@ bool ParseQueryOAConstraintSrcTypes(napi_env env, napi_callback_info cbInfo, if (argc == ARGS_SIZE_THREE) { if (!GetCallbackProperty(env, argv[argc - 1], asyncContext->callbackRef, 1)) { ACCOUNT_LOGE("Get callbackRef failed"); - std::string errMsg = "The type of arg " + std::to_string(argc) + " must be function"; + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -884,13 +884,13 @@ bool ParseQueryOAConstraintSrcTypes(napi_env env, napi_callback_info cbInfo, if (!GetIntProperty(env, argv[PARAMZERO], asyncContext->id)) { ACCOUNT_LOGE("Get id failed"); - std::string errMsg = "The type of arg 1 must be number"; + std::string errMsg = "Parameter error. The type of \"localId\" must be number"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } if (!GetStringProperty(env, argv[PARAMONE], asyncContext->constraint)) { ACCOUNT_LOGE("Get constraint failed"); - std::string errMsg = "The type of arg 2 must be string"; + std::string errMsg = "Parameter error. The type of \"constraint\" must be string"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1139,7 +1139,7 @@ bool ParseParaGetIdByUid(napi_env env, napi_callback_info cbInfo, GetIdByUidAsyn if (argc == ARGS_SIZE_TWO) { if (!GetCallbackProperty(env, argv[argc - 1], asyncContext->callbackRef, 1)) { ACCOUNT_LOGE("Get callbackRef failed"); - std::string errMsg = "The type of arg " + std::to_string(argc) + " must be function"; + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1147,7 +1147,7 @@ bool ParseParaGetIdByUid(napi_env env, napi_callback_info cbInfo, GetIdByUidAsyn if (!GetIntProperty(env, argv[PARAMZERO], asyncContext->uid)) { ACCOUNT_LOGE("Get uid failed"); - std::string errMsg = "The type of arg 1 must be number"; + std::string errMsg = "Parameter error. The type of \"uid\" must be number"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1763,14 +1763,14 @@ static bool ParseParamForActiveSubscriber(const napi_env &env, const std::string { if (argc < ARGS_SIZE_THREE) { ACCOUNT_LOGE("The arg number less than 3 characters"); - std::string errMsg = "The arg number must be at least 3 characters"; + std::string errMsg = "Parameter error. The number of parameters should be at least 3"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } if (argc >= ARGS_SIZE_THREE) { if (!GetCallbackProperty(env, argv[PARAMTWO], asyncContext->callbackRef, 1)) { ACCOUNT_LOGE("Get callbackRef failed"); - std::string errMsg = "The type of arg " + std::to_string(PARAMTWO + 1) + " must be function"; + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1786,14 +1786,14 @@ static bool ParseParamForActiveSubscriber(const napi_env &env, const std::string // argv[1] name: string if (!GetStringProperty(env, argv[PARAMONE], asyncContext->name)) { ACCOUNT_LOGE("Get name failed"); - std::string errMsg = "The type of arg 2 must be string"; + std::string errMsg = "Parameter error. The type of \"name\" must be string"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } size_t nameSize = asyncContext->name.size(); if (nameSize == 0 || nameSize > MAX_SUBSCRIBER_NAME_LEN) { ACCOUNT_LOGE("Subscriber name size %{public}zu is invalid.", nameSize); - std::string errMsg = "The length of arg 2 is invalid"; + std::string errMsg = "Parameter error. The length of \"name\" is invalid"; AccountNapiThrow(env, ERR_JS_INVALID_PARAMETER, errMsg, asyncContext->throwErr); return false; } @@ -1805,15 +1805,15 @@ static bool ParseParamForSwitchSubscriber(const napi_env &env, const std::string size_t argc, napi_value *argv) { if (argc < ARGS_SIZE_TWO) { - ACCOUNT_LOGE("The arg number less than 2 characters"); - std::string errMsg = "The arg number must be at least 2 characters"; + ACCOUNT_LOGE("The number of parameters should be at least 2"); + std::string errMsg = "Parameter error. The number of parameters should be at least 2"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } if (argc >= ARGS_SIZE_TWO) { if (!GetCallbackProperty(env, argv[PARAMONE], asyncContext->callbackRef, 1)) { ACCOUNT_LOGE("Get callbackRef failed"); - std::string errMsg = "The type of arg " + std::to_string(PARAMONE + 1) + " must be function"; + std::string errMsg = "Parameter error. The type of \"callback\" must be function"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1835,15 +1835,15 @@ bool ParseParaToSubscriber(const napi_env &env, napi_callback_info cbInfo, Subsc napi_value argv[ARGS_SIZE_THREE] = {nullptr}; NAPI_CALL_BASE(env, napi_get_cb_info(env, cbInfo, &argc, argv, thisVar, NULL), false); if (argc < ARGS_SIZE_TWO) { - ACCOUNT_LOGE("The arg number less than 2 characters."); - std::string errMsg = "The arg number must be at least 2 characters"; + ACCOUNT_LOGE("The number of parameters should be at least 2"); + std::string errMsg = "Parameter error. The number of parameters should be at least 2"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } std::string type; if (!GetStringProperty(env, argv[PARAMZERO], type)) { ACCOUNT_LOGE("Get type failed."); - std::string errMsg = "The type of arg 1 must be string"; + std::string errMsg = "Parameter error. The type of \"type\" must be string"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1854,7 +1854,7 @@ bool ParseParaToSubscriber(const napi_env &env, napi_callback_info cbInfo, Subsc return ParseParamForSwitchSubscriber(env, type, asyncContext, argc, argv); } ACCOUNT_LOGE("Get type fail, %{public}s is invalid.", type.c_str()); - std::string errMsg = "The type of arg 1 must be 'activate|activating|switched|switching'"; + std::string errMsg = "Parameter error. The content of \"type\" must be \"activate|activating|switched|switching\""; AccountNapiThrow(env, ERR_JS_INVALID_PARAMETER, errMsg, asyncContext->throwErr); return false; } @@ -1937,14 +1937,14 @@ bool ParseParaToUnsubscriber(const napi_env &env, napi_callback_info cbInfo, Uns NAPI_CALL_BASE(env, napi_get_cb_info(env, cbInfo, &argc, argv, thisVar, NULL), false); if (argc < ARGS_SIZE_ONE) { ACCOUNT_LOGE("The arg number less than 1 characters."); - std::string errMsg = "The arg number must be at least 1 characters"; + std::string errMsg = "Parameter error. The number of parameters should be at least 1"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } std::string type; if (!GetStringProperty(env, argv[PARAMZERO], type)) { ACCOUNT_LOGE("Get type failed."); - std::string errMsg = "The type of arg 1 must be string"; + std::string errMsg = "Parameter error. The type of \"type\" must be string"; AccountNapiThrow(env, ERR_JS_PARAMETER_ERROR, errMsg, asyncContext->throwErr); return false; } @@ -1955,7 +1955,7 @@ bool ParseParaToUnsubscriber(const napi_env &env, napi_callback_info cbInfo, Uns return ParseParamForSwitchUnsubscriber(env, type, asyncContext, argc, argv); } ACCOUNT_LOGE("Get type fail, %{public}s is invalid.", type.c_str()); - std::string errMsg = "The type of arg 1 must be 'activate|activating|switched|switching'"; + std::string errMsg = "Parameter error. The content of \"type\" must be \"activate|activating|switched|switching\""; AccountNapiThrow(env, ERR_JS_INVALID_PARAMETER, errMsg, asyncContext->throwErr); return false; }