/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/util/errcodes.cc
Line | Count | Source (jump to first uncovered line) |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. 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 distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | // Convert internal error code into readable texts. This text doesn't have to be English, and this |
16 | | // file can be translated into any languages that YugaByte supports. |
17 | | //-------------------------------------------------------------------------------------------------- |
18 | | #include "yb/yql/cql/ql/util/errcodes.h" |
19 | | |
20 | | #include "yb/common/ql_protocol.pb.h" |
21 | | #include "yb/util/enums.h" |
22 | | |
23 | | namespace yb { |
24 | | namespace ql { |
25 | | |
26 | | const std::unordered_map<ErrorCode, const char*, EnumHash> kQLErrorMessage { |
27 | | //------------------------------------------------------------------------------------------------ |
28 | | { ErrorCode::SUCCESS, "Success" }, |
29 | | |
30 | | //------------------------------------------------------------------------------------------------ |
31 | | // Warning. Start with 100. |
32 | | { ErrorCode::WARNING, "Warning" }, |
33 | | { ErrorCode::NOTFOUND, "Not Found" }, |
34 | | |
35 | | //------------------------------------------------------------------------------------------------ |
36 | | // System errors [-1, -9). |
37 | | { ErrorCode::FAILURE, "Internal Failure" }, |
38 | | { ErrorCode::SERVER_ERROR, "Server Error" }, |
39 | | { ErrorCode::STALE_METADATA, "Stale Metadata" }, |
40 | | { ErrorCode::UNAUTHORIZED, "Unauthorized"}, |
41 | | |
42 | | //------------------------------------------------------------------------------------------------ |
43 | | // Limitation related errors [-1, -50). |
44 | | { ErrorCode::LIMITATION_ERROR, "Implementation Limitation" }, |
45 | | { ErrorCode::SQL_STATEMENT_INVALID, "Invalid SQL Statement" }, |
46 | | { ErrorCode::CQL_STATEMENT_INVALID, "Invalid CQL Statement" }, |
47 | | { ErrorCode::FEATURE_NOT_YET_IMPLEMENTED, "Feature Not Yet Implemented" }, |
48 | | { ErrorCode::FEATURE_NOT_SUPPORTED, "Feature Not Supported" }, |
49 | | |
50 | | //------------------------------------------------------------------------------------------------ |
51 | | // Lexical errors [-50, -100). |
52 | | { ErrorCode::LEXICAL_ERROR, "Lexical Error" }, |
53 | | { ErrorCode::CHARACTER_NOT_IN_REPERTOIRE, "Character Not in Repertoire" }, |
54 | | { ErrorCode::INVALID_ESCAPE_SEQUENCE, "Invalid Escape Sequence" }, |
55 | | { ErrorCode::NAME_TOO_LONG, "Name Too Long" }, |
56 | | { ErrorCode::NONSTANDARD_USE_OF_ESCAPE_CHARACTER, "Nonstandard Use of Escape Character" }, |
57 | | |
58 | | //------------------------------------------------------------------------------------------------ |
59 | | // Syntax errors [-100, -200). |
60 | | { ErrorCode::SYNTAX_ERROR, "Syntax Error" }, |
61 | | { ErrorCode::INVALID_PARAMETER_VALUE, "Invalid Parameter Value" }, |
62 | | { ErrorCode::INVALID_COLUMN_DEFINITION, "Invalid Column Definition" }, |
63 | | |
64 | | //------------------------------------------------------------------------------------------------ |
65 | | // Semantic errors [-200, -300). |
66 | | { ErrorCode::SEM_ERROR, "Semantic Error" }, |
67 | | { ErrorCode::DATATYPE_MISMATCH, "Datatype Mismatch" }, |
68 | | { ErrorCode::DUPLICATE_OBJECT, "Duplicate Object" }, |
69 | | { ErrorCode::UNDEFINED_COLUMN, "Undefined Column" }, |
70 | | { ErrorCode::DUPLICATE_COLUMN, "Duplicate Column" }, |
71 | | { ErrorCode::MISSING_PRIMARY_KEY, "Missing Primary Key" }, |
72 | | { ErrorCode::INVALID_PRIMARY_COLUMN_TYPE, "Invalid Primary Key Column Datatype" }, |
73 | | { ErrorCode::MISSING_ARGUMENT_FOR_PRIMARY_KEY, "Missing Argument for Primary Key" }, |
74 | | { ErrorCode::NULL_ARGUMENT_FOR_PRIMARY_KEY, "Null Argument for Primary Key" }, |
75 | | { ErrorCode::INCOMPARABLE_DATATYPES, "Incomparable Datatypes" }, |
76 | | { ErrorCode::INVALID_TABLE_PROPERTY, "Invalid Table Property" }, |
77 | | { ErrorCode::DUPLICATE_TABLE_PROPERTY, "Duplicate Table Property" }, |
78 | | { ErrorCode::INVALID_DATATYPE, "Invalid Datatype" }, |
79 | | { ErrorCode::SYSTEM_NAMESPACE_READONLY, "System Namespace is Read-Only" }, |
80 | | { ErrorCode::INVALID_FUNCTION_CALL, "Invalid Function Call" }, |
81 | | { ErrorCode::NO_NAMESPACE_USED, "No Namespace Used" }, |
82 | | { ErrorCode::INSERT_TABLE_OF_COUNTERS, "Insert into table of counters not allowed" }, |
83 | | { ErrorCode::INVALID_COUNTING_EXPR, "Counters can only be incremented or decremented" }, |
84 | | { ErrorCode::DUPLICATE_TYPE, "Duplicate Type" }, |
85 | | { ErrorCode::DUPLICATE_TYPE_FIELD, "Duplicate Type Field" }, |
86 | | { ErrorCode::ALTER_KEY_COLUMN, "Alter key column" }, |
87 | | { ErrorCode::INCOMPATIBLE_COPARTITION_SCHEMA, "Incompatible Copartition Schema" }, |
88 | | { ErrorCode::INVALID_ROLE_DEFINITION, "Invalid Role Definition" }, |
89 | | { ErrorCode::DUPLICATE_ROLE, "Duplicate Role"}, |
90 | | { ErrorCode::NULL_IN_COLLECTIONS, "null is not supported inside collections"}, |
91 | | { ErrorCode::INVALID_UPDATE_PROPERTY, "Invalid Update Property" }, |
92 | | { ErrorCode::DUPLICATE_UPDATE_PROPERTY, "Duplicate Update Property" }, |
93 | | |
94 | | //------------------------------------------------------------------------------------------------ |
95 | | // Execution errors [-300, x). |
96 | | { ErrorCode::EXEC_ERROR, "Execution Error" }, |
97 | | { ErrorCode::OBJECT_NOT_FOUND, "Object Not Found" }, |
98 | | { ErrorCode::INVALID_TABLE_DEFINITION, "Invalid Table Definition" }, |
99 | | { ErrorCode::WRONG_METADATA_VERSION, "Wrong Metadata Version" }, |
100 | | { ErrorCode::INVALID_ARGUMENTS, "Invalid Arguments" }, |
101 | | { ErrorCode::TOO_FEW_ARGUMENTS, "Too Few Arguments" }, |
102 | | { ErrorCode::TOO_MANY_ARGUMENTS, "Too Many Arguments" }, |
103 | | { ErrorCode::KEYSPACE_ALREADY_EXISTS, "Keyspace Already Exists" }, |
104 | | { ErrorCode::KEYSPACE_NOT_FOUND, "Keyspace Not Found" }, |
105 | | { ErrorCode::TABLET_NOT_FOUND, "Tablet Not Found" }, |
106 | | { ErrorCode::UNPREPARED_STATEMENT, "Unprepared Statement" }, |
107 | | { ErrorCode::TYPE_NOT_FOUND, "Type Not Found" }, |
108 | | { ErrorCode::INVALID_TYPE_DEFINITION, "Invalid Type Definition" }, |
109 | | { ErrorCode::RESTART_REQUIRED, "Restart Required" }, |
110 | | { ErrorCode::ROLE_NOT_FOUND, "Role Not Found"}, |
111 | | { ErrorCode::RESOURCE_NOT_FOUND, "Resource Not Found"}, |
112 | | { ErrorCode::INVALID_REQUEST, "Invalid Request"}, |
113 | | { ErrorCode::PERMISSION_NOT_FOUND, "Permission Not Found"}, |
114 | | { ErrorCode::CONDITION_NOT_SATISFIED, "Condition Not Satisfied"}, |
115 | | }; |
116 | | |
117 | 15.8k | ErrorCode GetErrorCode(const Status& s) { |
118 | 15.8k | QLError ql_error(s); |
119 | 15.8k | return ql_error != ErrorCode::SUCCESS ? ql_error.value() : ErrorCode::FAILURE; |
120 | 15.8k | } |
121 | | |
122 | 11.2k | const char *ErrorText(const ErrorCode error_code) { |
123 | 11.2k | auto it = kQLErrorMessage.find(error_code); |
124 | 11.2k | if (it == kQLErrorMessage.end()) { |
125 | 0 | LOG(DFATAL) << "Unknown error code: " << to_underlying(error_code); |
126 | 0 | return "Unknown error"; |
127 | 0 | } |
128 | 11.2k | return it->second; |
129 | 11.2k | } |
130 | | |
131 | 2.24k | Status ErrorStatus(const ErrorCode code, const std::string& mesg) { |
132 | 2.24k | return STATUS(QLError, ErrorText(code), mesg, QLError(code)); |
133 | 2.24k | } |
134 | | |
135 | 0 | std::string FormatForComparisonFailureMessage(ErrorCode op, ErrorCode) { |
136 | 0 | return ErrorText(op); |
137 | 0 | } |
138 | | |
139 | 2.04k | ErrorCode QLStatusToErrorCode(QLResponsePB::QLStatus status) { |
140 | 2.04k | switch (status) { |
141 | 0 | case QLResponsePB::YQL_STATUS_OK: |
142 | 0 | return ErrorCode::SUCCESS; |
143 | 1.67k | case QLResponsePB::YQL_STATUS_SCHEMA_VERSION_MISMATCH: |
144 | 1.67k | return ErrorCode::WRONG_METADATA_VERSION; |
145 | 0 | case QLResponsePB::YQL_STATUS_RUNTIME_ERROR: |
146 | 0 | return ErrorCode::SERVER_ERROR; |
147 | 345 | case QLResponsePB::YQL_STATUS_USAGE_ERROR: |
148 | 345 | return ErrorCode::EXEC_ERROR; |
149 | 0 | case QLResponsePB::YQL_STATUS_RESTART_REQUIRED_ERROR: |
150 | 0 | return ErrorCode::RESTART_REQUIRED; |
151 | 25 | case QLResponsePB::YQL_STATUS_QUERY_ERROR: |
152 | 25 | return ErrorCode::EXEC_ERROR; |
153 | 0 | } |
154 | 0 | FATAL_INVALID_ENUM_VALUE(QLResponsePB::QLStatus, status); |
155 | 0 | } |
156 | | |
157 | | static const std::string kQLErrorCategoryName = "ql error"; |
158 | | |
159 | | static StatusCategoryRegisterer ql_error_category_registerer( |
160 | | StatusCategoryDescription::Make<QLErrorTag>(&kQLErrorCategoryName)); |
161 | | |
162 | | } // namespace ql |
163 | | } // namespace yb |