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