/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/util/errcodes.h
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 | | // SQL error codes. |
15 | | // - All error code must be < ErrorCode::SUCCESS |
16 | | // Compilation or execution should eventually stop after an error is raised. |
17 | | // - All warning code must be > ErrorCode::SUCCESS |
18 | | // Compilation and execution should continue after a warning is raised. |
19 | | //-------------------------------------------------------------------------------------------------- |
20 | | |
21 | | #ifndef YB_YQL_CQL_QL_UTIL_ERRCODES_H_ |
22 | | #define YB_YQL_CQL_QL_UTIL_ERRCODES_H_ |
23 | | |
24 | | #include "yb/util/status_ec.h" |
25 | | |
26 | | // Return an unauthorized error if authentication is not enabled through the flag |
27 | | // use_cassandra_authentication. |
28 | 2.36k | #define RETURN_NOT_AUTH_ENABLED(s) do { \ |
29 | 2.36k | if (!FLAGS_use_cassandra_authentication) { \ |
30 | 0 | return s->Error(this, "You have to be logged in and not anonymous to perform this request", \ |
31 | 0 | ErrorCode::UNAUTHORIZED); \ |
32 | 0 | } \ |
33 | 2.36k | } while (false); |
34 | | |
35 | | namespace yb { |
36 | | namespace ql { |
37 | | |
38 | | enum class ErrorCode : int64_t { |
39 | | //------------------------------------------------------------------------------------------------ |
40 | | // All error codes < SUCCESS |
41 | | // All warning codes > SUCCESS |
42 | | SUCCESS = 0, |
43 | | |
44 | | //------------------------------------------------------------------------------------------------ |
45 | | // Warning. [1, +) |
46 | | WARNING = 1, |
47 | | NOTFOUND = 100, |
48 | | |
49 | | //------------------------------------------------------------------------------------------------ |
50 | | // System Error [-1, -9) |
51 | | // Failure with no specific reason. Most likely, this is used for a system or coding error. |
52 | | FAILURE = -1, |
53 | | SERVER_ERROR = -2, |
54 | | STALE_METADATA = -3, |
55 | | UNAUTHORIZED = -4, |
56 | | |
57 | | //------------------------------------------------------------------------------------------------ |
58 | | // Limitation errors [-10, -50). |
59 | | LIMITATION_ERROR = -10, |
60 | | |
61 | | // SQL specific error codes. CQL might not support certain SQL syntax and vice versa. |
62 | | SQL_STATEMENT_INVALID = -11, |
63 | | // CQL specific error codes. CQL might not support certain SQL syntax and vice versa. |
64 | | CQL_STATEMENT_INVALID = -12, |
65 | | |
66 | | FEATURE_NOT_YET_IMPLEMENTED = -13, |
67 | | FEATURE_NOT_SUPPORTED = -14, |
68 | | |
69 | | //------------------------------------------------------------------------------------------------ |
70 | | // Lexical errors [-50, -100). |
71 | | LEXICAL_ERROR = -50, |
72 | | CHARACTER_NOT_IN_REPERTOIRE = -51, |
73 | | INVALID_ESCAPE_SEQUENCE = -52, |
74 | | NAME_TOO_LONG = -53, |
75 | | NONSTANDARD_USE_OF_ESCAPE_CHARACTER = -55, |
76 | | |
77 | | //------------------------------------------------------------------------------------------------ |
78 | | // Syntax errors [-100, -200). |
79 | | SYNTAX_ERROR = -100, |
80 | | INVALID_PARAMETER_VALUE = -101, |
81 | | INVALID_COLUMN_DEFINITION = -102, |
82 | | |
83 | | //------------------------------------------------------------------------------------------------ |
84 | | // Semantic errors [-200, -300). |
85 | | SEM_ERROR = -200, |
86 | | DATATYPE_MISMATCH = -201, |
87 | | DUPLICATE_OBJECT = -202, |
88 | | UNDEFINED_COLUMN = -203, |
89 | | DUPLICATE_COLUMN = -204, |
90 | | MISSING_PRIMARY_KEY = -205, |
91 | | INVALID_PRIMARY_COLUMN_TYPE = -206, |
92 | | MISSING_ARGUMENT_FOR_PRIMARY_KEY = -207, |
93 | | NULL_ARGUMENT_FOR_PRIMARY_KEY = -208, |
94 | | INCOMPARABLE_DATATYPES = -209, |
95 | | INVALID_TABLE_PROPERTY = -210, |
96 | | DUPLICATE_TABLE_PROPERTY = -211, |
97 | | INVALID_DATATYPE = -212, |
98 | | SYSTEM_NAMESPACE_READONLY = -213, |
99 | | INVALID_FUNCTION_CALL = -214, |
100 | | NO_NAMESPACE_USED = -215, |
101 | | INSERT_TABLE_OF_COUNTERS = -216, |
102 | | INVALID_COUNTING_EXPR = -217, |
103 | | DUPLICATE_TYPE = -218, |
104 | | DUPLICATE_TYPE_FIELD = -219, |
105 | | ALTER_KEY_COLUMN = -220, |
106 | | INCOMPATIBLE_COPARTITION_SCHEMA = -221, |
107 | | INVALID_ROLE_DEFINITION = -222, |
108 | | DUPLICATE_ROLE = -223, |
109 | | NULL_IN_COLLECTIONS = -224, |
110 | | DUPLICATE_UPDATE_PROPERTY = -225, |
111 | | INVALID_UPDATE_PROPERTY = -226, |
112 | | |
113 | | //------------------------------------------------------------------------------------------------ |
114 | | // Execution errors [-300, x). |
115 | | EXEC_ERROR = -300, |
116 | | OBJECT_NOT_FOUND = -301, |
117 | | INVALID_TABLE_DEFINITION = -302, |
118 | | WRONG_METADATA_VERSION = -303, |
119 | | INVALID_ARGUMENTS = -304, |
120 | | TOO_FEW_ARGUMENTS = -305, |
121 | | TOO_MANY_ARGUMENTS = -306, |
122 | | KEYSPACE_ALREADY_EXISTS = -307, |
123 | | KEYSPACE_NOT_FOUND = -308, |
124 | | TABLET_NOT_FOUND = -309, |
125 | | UNPREPARED_STATEMENT = -310, |
126 | | TYPE_NOT_FOUND = -311, |
127 | | INVALID_TYPE_DEFINITION = -312, |
128 | | RESTART_REQUIRED = -313, |
129 | | ROLE_NOT_FOUND = -314, |
130 | | RESOURCE_NOT_FOUND = -315, |
131 | | INVALID_REQUEST = -316, |
132 | | PERMISSION_NOT_FOUND = -317, |
133 | | CONDITION_NOT_SATISFIED = -318, |
134 | | |
135 | | }; |
136 | | |
137 | | // Return SQL error code from an Status if it is a SQL error. Otherwise, return FAILURE. |
138 | | ErrorCode GetErrorCode(const Status& s); |
139 | | |
140 | | // Mapping errcode to text messages. |
141 | | const char *ErrorText(ErrorCode code); |
142 | | |
143 | | // Return an error status with the error code. |
144 | | Status ErrorStatus(ErrorCode code, const std::string& mesg = ""); |
145 | | |
146 | | // Font for error message is RED. |
147 | | constexpr const char *kErrorFontStart = "\033[31m"; |
148 | | constexpr const char *kErrorFontEnd = "\033[0m"; |
149 | | |
150 | | std::string FormatForComparisonFailureMessage(ErrorCode op, ErrorCode other); |
151 | | |
152 | | struct QLErrorTag : IntegralErrorTag<ErrorCode> { |
153 | | // This category id is part of the wire protocol and should not be changed once released. |
154 | | static constexpr uint8_t kCategory = 4; |
155 | | |
156 | 0 | static std::string ToMessage(Value code) { |
157 | 0 | return ErrorText(code); |
158 | 0 | } |
159 | | }; |
160 | | |
161 | | typedef StatusErrorCodeImpl<QLErrorTag> QLError; |
162 | | |
163 | | } // namespace ql |
164 | | } // namespace yb |
165 | | |
166 | | #endif // YB_YQL_CQL_QL_UTIL_ERRCODES_H_ |