/Users/deen/code/yugabyte-db/src/yb/common/pgsql_error.h
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_COMMON_PGSQL_ERROR_H |
15 | | #define YB_COMMON_PGSQL_ERROR_H |
16 | | |
17 | | #include "yb/common/pgsql_protocol.pb.h" |
18 | | |
19 | | #include "yb/util/status_fwd.h" |
20 | | #include "yb/util/status_ec.h" |
21 | | #include "yb/util/yb_pg_errcodes.h" |
22 | | |
23 | | namespace yb { |
24 | | |
25 | | struct PgsqlErrorTag : IntegralErrorTag<YBPgErrorCode> { |
26 | | // It is part of the wire protocol and should not be changed once released. |
27 | | static constexpr uint8_t kCategory = 6; |
28 | | |
29 | 660k | static std::string ToMessage(Value value) { |
30 | 660k | return ToString(value); |
31 | 660k | } |
32 | | |
33 | 471k | static std::string DecodeToString(const uint8_t* source) { |
34 | 471k | return ToMessage(Decode(source)); |
35 | 471k | } |
36 | | |
37 | | }; |
38 | | |
39 | | typedef StatusErrorCodeImpl<PgsqlErrorTag> PgsqlError; |
40 | | |
41 | | struct PgsqlRequestStatusTag : IntegralErrorTag<PgsqlResponsePB::RequestStatus> { |
42 | | // It is part of the wire protocol and should not be changed once released. |
43 | | static constexpr uint8_t kCategory = 17; |
44 | | |
45 | 474 | static std::string ToMessage(Value value) { |
46 | 474 | return PgsqlResponsePB::RequestStatus_Name(value); |
47 | 474 | } |
48 | | |
49 | 474 | static std::string DecodeToString(const uint8_t* source) { |
50 | 474 | return ToMessage(Decode(source)); |
51 | 474 | } |
52 | | |
53 | | }; |
54 | | |
55 | | typedef StatusErrorCodeImpl<PgsqlRequestStatusTag> PgsqlRequestStatus; |
56 | | |
57 | | struct OpIndexTag : IntegralErrorTag<size_t> { |
58 | | // It is part of the wire protocol and should not be changed once released. |
59 | | static constexpr uint8_t kCategory = 18; |
60 | | |
61 | 474 | static std::string ToMessage(Value value) { |
62 | 474 | return std::to_string(value); |
63 | 474 | } |
64 | | |
65 | 474 | static std::string DecodeToString(const uint8_t* source) { |
66 | 474 | return ToMessage(Decode(source)); |
67 | 474 | } |
68 | | |
69 | | }; |
70 | | |
71 | | typedef StatusErrorCodeImpl<OpIndexTag> OpIndex; |
72 | | |
73 | | } // namespace yb |
74 | | |
75 | | #endif // YB_COMMON_PGSQL_ERROR_H |