• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "napi/native_api.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_NOT_SUPPORT_CROSS_APP_START = 16000018,
42     ERR_ABILITY_RUNTIME_EXTERNAL_CANNOT_MATCH_ANY_COMPONENT = 16000019,
43     ERR_ABILITY_RUNTIME_EXTERNAL_NOT_ABILITY_CONTEXT = 16000020,
44     ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR = 16000050,
45     ERR_ABILITY_RUNTIME_EXTERNAL_NETWORK_ERROR = 16000051,
46     ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_NOT_SUPPORT = 16000052,
47     ERR_ABILITY_RUNTIME_EXTERNAL_NOT_TOP_ABILITY = 16000053,
48     ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_BUSY = 16000054,
49     ERR_ABILITY_RUNTIME_EXTERNAL_FREE_INSTALL_TIMEOUT = 16000055,
50     ERR_ABILITY_RUNTIME_EXTERNAL_CANNOT_FREE_INSTALL_OTHER_ABILITY = 16000056,
51     ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SUPPORT_CROSS_DEVICE_FREE_INSTALL = 16000057,
52     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_FLAG = 16000058,
53     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_URI_TYPE = 16000059,
54     ERR_ABILITY_RUNTIME_EXTERNAL_GRANT_URI_PERMISSION = 16000060,
55     ERR_ABILITY_RUNTIME_OPERATION_NOT_SUPPORTED = 16000061,
56     ERR_ABILITY_RUNTIME_CHILD_PROCESS_NUMBER_EXCEEDS_UPPER_BOUND = 16000062,
57     ERR_ABILITY_RUNTIME_RESTART_APP_INCORRECT_ABILITY = 16000063,
58     ERR_ABILITY_RUNTIME_RESTART_APP_FREQUENT = 16000064,
59     ERR_ABILITY_RUNTIME_EXTERNAL_EXECUTE_SHELL_COMMAND_FAILED = 16000101,
60     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT = 16000151,
61     ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_NOT_FOUND = 16000152,
62     ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_CANCELED = 16000153,
63 
64     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_URI_ABILITY = 16100001,
65     ERR_ABILITY_RUNTIME_EXTERNAL_FA_NOT_SUPPORT_OPERATION = 16100002,
66 
67     ERR_ABILITY_RUNTIME_EXTERNAL_CALLER_RELEASED = 16200001,
68     ERR_ABILITY_RUNTIME_EXTERNAL_CALLEE_INVALID = 16200002,
69     ERR_ABILITY_RUNTIME_EXTERNAL_RELEASE_ERROR = 16200003,
70     ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_REGISTERED = 16200004,
71     ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_NOT_REGISTERED = 16200005,
72 
73     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION = 16300001,
74     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION_LISTENER = 16300002,
75 
76     ERR_ABILITY_RUNTIME_EXTERNAL_NOT_SYSTEM_HSP = 16400001,
77 
78     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_BUNDLENAME = 18500001,
79     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_HQF = 18500002,
80     ERR_ABILITY_RUNTIME_EXTERNAL_DEPLOY_HQF_FAILED = 18500003,
81     ERR_ABILITY_RUNTIME_EXTERNAL_SWITCH_HQF_FAILED = 18500004,
82     ERR_ABILITY_RUNTIME_EXTERNAL_DELETE_HQF_FAILED = 18500005,
83     ERR_ABILITY_RUNTIME_EXTERNAL_LOAD_PATCH_FAILED = 18500006,
84     ERR_ABILITY_RUNTIME_EXTERNAL_UNLOAD_PATCH_FAILED = 18500007,
85     ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008,
86 
87     ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201,
88     ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP = 202,
89     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401,
90     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801,
91 };
92 
93 class AbilityRuntimeErrorUtil {
94 public:
95     /**
96      * @brief Throw an runtime exception for js.
97      * @param engine js runtime engine.
98      * @param errCode external errorcode.
99      * @param errMessage error msg.
100      * @return true if success.
101      */
102     static bool Throw(napi_env env, int32_t errCode, const std::string &errMessage = "");
103 
104     /**
105      * @brief Throw an runtime exception for js with internal error code.
106      * @param engine js runtime engine.
107      * @param errCode internal errorcode.
108      * @return true if success.
109      */
110     static bool ThrowByInternalErrCode(napi_env env, int32_t errCode);
111 
112     /**
113      * @brief Create a Error By Internal errorCode
114      * @param engine js runtime engine.
115      * @param errCode internal errorcode.
116      * @return js error object.
117      */
118     static napi_value CreateErrorByInternalErrCode(napi_env env, int32_t errCode);
119 
120     /**
121      * @brief Get error message By error code
122      * @param errCode internal errorcode.
123      * @return error message.
124      */
125     static std::string GetErrMessage(int32_t errCode);
126 };
127 } // namespace AbilityRuntime
128 } // namespace OHOS
129 #endif // OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H
130