• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "napi_gdb_error.h"
17 
18 #include <algorithm>
19 
20 #include "gdb_errors.h"
21 
22 namespace OHOS::GraphStoreJsKit {
23 using namespace DistributedDataAip;
24 static constexpr JsErrorCode JS_ERROR_CODE_MSGS[] = {
25     { E_INVALID_ARGS, 401, "Parameter error." },
26     { E_GRD_DATA_CORRUPTED, 31300001, "Database corrupted." },
27     { E_GRD_DB_INSTANCE_ABNORMAL, 31300002, "Already closed." },
28     { E_DATABASE_BUSY, 31300003, "The database is busy." },
29     { E_GRD_FAILED_MEMORY_ALLOCATE, 31300004, "The database is out of memory." },
30     { E_GRD_DISK_SPACE_FULL, 31300005, "The database is full." },
31     { E_GRD_DUPLICATE_PARAM, 31300006,
32         "A duplicate graph name, vertex or edge type, or vertex or edge property name exists." },
33     { E_GRD_UNDEFINED_PARAM, 31300007,
34         "The graph name, vertex or edge type, or vertex or edge property is not defined." },
35     { E_GRD_INVALID_NAME, 31300008,
36         "The graph name, vertex or edge type, or vertex or edge property name does not conform to constraints." },
37     { E_GRD_SYNTAX_ERROR, 31300009, "The GQL statement syntax error." },
38     { E_GRD_SEMANTIC_ERROR, 31300010, "The GQL statement semantic error." },
39     { E_GRD_OVER_LIMIT, 31300012,
40         "The number of graph names, vertex or edge types, or vertex or edge properties exceeds the limit." },
41     { E_GRD_DATA_CONFLICT, 31300013, "A conflicting constraint already exists." },
42     { E_DBPATH_ACCESS_FAILED, 31300014, "Invalid database path." },
43     { E_CONFIG_INVALID_CHANGE, 31300015, "Config changed." },
44 };
45 
GetJsErrorCode(int32_t errorCode)46 std::optional<JsErrorCode> GetJsErrorCode(int32_t errorCode)
47 {
48     auto jsErrorCode = JsErrorCode{ errorCode, -1, "" };
49     auto iter = std::lower_bound(JS_ERROR_CODE_MSGS,
50         JS_ERROR_CODE_MSGS + sizeof(JS_ERROR_CODE_MSGS) / sizeof(JS_ERROR_CODE_MSGS[0]), jsErrorCode,
51         [](const JsErrorCode &jsErrorCode1, const JsErrorCode &jsErrorCode2) {
52             return jsErrorCode1.status < jsErrorCode2.status;
53         });
54     if (iter < JS_ERROR_CODE_MSGS + sizeof(JS_ERROR_CODE_MSGS) / sizeof(JS_ERROR_CODE_MSGS[0]) &&
55         iter->status == errorCode) {
56         return *iter;
57     }
58     return std::nullopt;
59 }
60 } // namespace OHOS::GraphStoreJsKit