1 /*
2 * Copyright (c) 2025 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 #include "napi_error.h"
16
17 #include <map>
18 namespace OHOS {
19 namespace HiviewDFX {
20 namespace NapiError {
GetErrorMsg(int errCode)21 std::string GetErrorMsg(int errCode)
22 {
23 const std::map<int, const char *> errMap = {
24 // common api error
25 { ERR_PARAM, "Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect "\
26 "parameter types; 3.Parameter verification failed." },
27 // business error of write function
28 { ERR_DISABLE, "Function disabled. Possible caused by the param disable in ConfigOption is true." },
29 { ERR_INVALID_DOMAIN,
30 "Invalid event domain. Possible causes: 1. Contain invalid characters; 2. Length is invalid." },
31 { ERR_INVALID_NAME,
32 "Invalid event name. Possible causes: 1. Contain invalid characters; 2. Length is invalid." },
33 { ERR_INVALID_PARAM_NUM,
34 "Invalid number of event parameters. Possible caused by the number of parameters is over 32." },
35 { ERR_INVALID_STR_LEN, "Invalid string length of the event parameter." },
36 { ERR_INVALID_KEY,
37 "Invalid event parameter name. Possible causes: 1. Contain invalid characters; 2. Length is invalid." },
38 { ERR_INVALID_ARR_LEN, "Invalid array length of the event parameter." },
39 { ERR_INVALID_CUSTOM_PARAM_NUM, "The number of parameter keys exceeds the limit." },
40 // business error of addWatcher function
41 { ERR_INVALID_WATCHER_NAME,
42 "Invalid watcher name. Possible causes: 1. Contain invalid characters; 2. Length is invalid." },
43 { ERR_INVALID_FILTER_DOMAIN,
44 "Invalid filtering event domain. Possible causes: 1. Contain invalid characters; 2. Length is invalid." },
45 { ERR_INVALID_COND_ROW, "Invalid row value. Possible caused by the row value is less than zero." },
46 { ERR_INVALID_COND_SIZE, "Invalid size value. Possible caused by the size value is less than zero." },
47 { ERR_INVALID_COND_TIMEOUT, "Invalid timeout value. Possible caused by the timeout value is less than zero." },
48 // business error of configure function
49 { ERR_INVALID_MAX_STORAGE, "Invalid max storage quota value. Possible caused by incorrectly formatted." },
50 // business error of AppEventPackageHolder.setSize function
51 { ERR_INVALID_SIZE, "Invalid size value. Possible caused by the size value is less than or equal to zero."},
52 // business error for incorrect parameter length or format
53 { ERR_INVALID_PARAM_VALUE,
54 "Invalid parameter value. Possible causes: 1. Incorrect parameter length; 2. Incorrect parameter format." }
55 };
56 auto it = errMap.find(errCode);
57 return it == errMap.end() ? "ErrorMsg undefined" : it->second;
58 }
59 } // namespace NapiError
60 } // namespace HiviewDFX
61 } // namespace OHOS