1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H 17 #define OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H 18 19 #include <string> 20 #include "js_runtime_utils.h" 21 22 namespace OHOS { 23 namespace AbilityRuntime { 24 enum { 25 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_ABILITY_NAME = 16000001, 26 ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_OPERATION = 16000002, 27 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_ID = 16000003, 28 ERR_ABILITY_RUNTIME_EXTERNAL_VISIBILITY_VERIFICATION_FAILED = 16000004, 29 ERR_ABILITY_RUNTIME_EXTERNAL_CROSS_USER_OPERATION = 16000006, 30 ERR_ABILITY_RUNTIME_EXTERNAL_SERVICE_BUSY = 16000007, 31 ERR_ABILITY_RUNTIME_EXTERNAL_CROWDTEST_APP_EXPIRATION = 16000008, 32 ERR_ABILITY_RUNTIME_EXTERNAL_WUKONG_MODE = 16000009, 33 ERR_ABILITY_RUNTIME_EXTERNAL_OPERATION_WITH_CONTINUE_FLAG = 16000010, 34 ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST = 16000011, 35 ERR_ABILITY_RUNTIME_EXTERNAL_ABILITY_ALREADY_AT_TOP = 16000012, 36 ERR_ABILITY_RUNTIME_EXTERNAL_CONNECTION_NOT_EXIST = 16000013, 37 ERR_ABILITY_RUNTIME_EXTERNAL_CONNECTION_STATE_ABNORMAL = 16000014, 38 ERR_ABILITY_RUNTIME_EXTERNAL_SERVICE_TIMEOUT = 16000015, 39 ERR_ABILITY_RUNTIME_EXTERNAL_APP_UNDER_CONTROL = 16000016, 40 ERR_ABILITY_RUNTIME_EXTERNAL_START_ABILITY_WAITTING = 16000017, 41 ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR = 16000050, 42 ERR_ABILITY_RUNTIME_EXTERNAL_NETWORK_ERROR = 16000051, 43 ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_NOT_SUPPORT = 16000052, 44 ERR_ABILITY_RUNTIME_EXTERNAL_NOT_TOP_ABILITY = 16000053, 45 ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_BUSY = 16000054, 46 ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_TIMEOUT = 16000055, 47 ERR_ABILITY_RUNTIME_EXTERNAL_CANNOT_FREE_INSTALL_OTHER_ABILITY = 16000056, 48 ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL = 16000057, 49 ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_FLAG = 16000058, 50 ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_TYPE = 16000059, 51 ERR_ABILITY_RUNTIME_EXTERNAL_GRANT_URI_PERMISSION = 16000060, 52 ERR_ABILITY_RUNTIME_EXTERNAL_EXECUTE_SHELL_COMMAND_FAILED = 16000101, 53 ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT = 16000151, 54 ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_NOT_FOUND = 16000152, 55 ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_CANCELED = 16000153, 56 57 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_URI_ABILITY = 16100001, 58 ERR_ABILITY_RUNTIME_EXTERNAL_FA_NOT_SUPPORT_OPERATION = 16100002, 59 60 ERR_ABILITY_RUNTIME_EXTERNAL_CALLER_RELEASED = 16200001, 61 ERR_ABILITY_RUNTIME_EXTERNAL_CALLEE_INVALID = 16200002, 62 ERR_ABILITY_RUNTIME_EXTERNAL_RELEASE_ERROR = 16200003, 63 ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_REGISTERED = 16200004, 64 ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_NOT_REGISTERED = 16200005, 65 66 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION = 16300001, 67 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION_LISTENER = 16300002, 68 69 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_BUNDLENAME = 18500001, 70 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_HQF = 18500002, 71 ERR_ABILITY_RUNTIME_EXTERNAL_DEPLOY_HQF_FAILED = 18500003, 72 ERR_ABILITY_RUNTIME_EXTERNAL_SWITCH_HQF_FAILED = 18500004, 73 ERR_ABILITY_RUNTIME_EXTERNAL_DELETE_HQF_FAILED = 18500005, 74 ERR_ABILITY_RUNTIME_EXTERNAL_LOAD_PATCH_FAILED = 18500006, 75 ERR_ABILITY_RUNTIME_EXTERNAL_UNLOAD_PATCH_FAILED = 18500007, 76 ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008, 77 78 ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201, 79 ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP = 202, 80 ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401, 81 ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801, 82 }; 83 84 class AbilityRuntimeErrorUtil { 85 public: 86 /** 87 * @brief Throw an runtime exception for js. 88 * 89 * @param engine js runtime engine. 90 * @param errCode external errorcode. 91 * @param errMessage error msg. 92 * @return true if success. 93 */ 94 static bool Throw(NativeEngine &engine, int32_t errCode, const std::string &errMessage = ""); 95 96 /** 97 * @brief Throw an runtime exception for js with internal error code. 98 * 99 * @param engine js runtime engine. 100 * @param errCode internal errorcode. 101 * @return true if success. 102 */ 103 static bool ThrowByInternalErrCode(NativeEngine &engine, int32_t errCode); 104 105 /** 106 * @brief Create a Error By Internal errorCode 107 * 108 * @param engine js runtime engine. 109 * @param errCode internal errorcode. 110 * @return js error object. 111 */ 112 static NativeValue *CreateErrorByInternalErrCode(NativeEngine &engine, int32_t errCode); 113 114 /** 115 * @brief Get error message By error code 116 * 117 * @param errCode internal errorcode. 118 * @return error message. 119 */ 120 static std::string GetErrMessage(int32_t errCode); 121 }; 122 } // namespace AbilityRuntime 123 } // namespace OHOS 124 #endif // OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H