• 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 "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_EXECUTE_SHELL_COMMAND_FAILED = 16000101,
50     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT = 16000151,
51     ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_NOT_FOUND = 16000152,
52     ERR_ABILITY_RUNTIME_EXTERNAL_WANTAGENT_CANCELED = 16000153,
53 
54     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_URI_ABILITY = 16100001,
55     ERR_ABILITY_RUNTIME_EXTERNAL_FA_NOT_SUPPORT_OPERATION = 16100002,
56 
57     ERR_ABILITY_RUNTIME_EXTERNAL_CALLER_RELEASED = 16200001,
58     ERR_ABILITY_RUNTIME_EXTERNAL_CALLEE_INVALID = 16200002,
59     ERR_ABILITY_RUNTIME_EXTERNAL_RELEASE_ERROR = 16200003,
60     ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_REGISTERED = 16200004,
61     ERR_ABILITY_RUNTIME_EXTERNAL_METHOED_NOT_REGISTERED = 16200005,
62 
63     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION = 16300001,
64     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_MISSION_LISTENER = 16300002,
65 
66     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_BUNDLENAME = 18500001,
67     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_HQF = 18500002,
68     ERR_ABILITY_RUNTIME_EXTERNAL_DEPLOY_HQF_FAILED = 18500003,
69     ERR_ABILITY_RUNTIME_EXTERNAL_SWITCH_HQF_FAILED = 18500004,
70     ERR_ABILITY_RUNTIME_EXTERNAL_DELETE_HQF_FAILED = 18500005,
71     ERR_ABILITY_RUNTIME_EXTERNAL_LOAD_PATCH_FAILED = 18500006,
72     ERR_ABILITY_RUNTIME_EXTERNAL_UNLOAD_PATCH_FAILED = 18500007,
73     ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008,
74 
75     ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201,
76     ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401,
77     ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801,
78 };
79 
80 class AbilityRuntimeErrorUtil {
81 public:
82     /**
83      * @brief Throw an runtime exception for js.
84      *
85      * @param engine js runtime engine.
86      * @param errCode external errorcode.
87      * @param errMessage error msg.
88      * @return true if success.
89      */
90     static bool Throw(NativeEngine &engine, int32_t errCode, const std::string &errMessage = "");
91 
92     /**
93      * @brief Throw an runtime exception for js with internal error code.
94      *
95      * @param engine js runtime engine.
96      * @param errCode internal errorcode.
97      * @return true if success.
98      */
99     static bool ThrowByInternalErrCode(NativeEngine &engine, int32_t errCode);
100 
101     /**
102      * @brief Create a Error By Internal errorCode
103      *
104      * @param engine js runtime engine.
105      * @param errCode internal errorcode.
106      * @return js error object.
107      */
108     static NativeValue *CreateErrorByInternalErrCode(NativeEngine &engine, int32_t errCode);
109 
110     /**
111      * @brief Get error message By error code
112      *
113      * @param errCode internal errorcode.
114      * @return error message.
115      */
116     static std::string GetErrMessage(int32_t errCode);
117 };
118 } // namespace AbilityRuntime
119 } // namespace OHOS
120 #endif // OHOS_ABILITY_RUNTIME_ABILITY_RUNTIME_ERROR_UTIL_H