11#include <userver/storages/postgres/dsn.hpp>
12#include <userver/storages/postgres/io/traits.hpp>
13#include <userver/storages/postgres/message.hpp>
15#include <userver/compiler/demangle.hpp>
16#include <userver/utils/underlying_value.hpp>
18USERVER_NAMESPACE_BEGIN
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
168class Error :
public std::runtime_error {
169 using runtime_error::runtime_error;
191template <
typename Base>
194 explicit ServerError(
const Message& msg)
195 : Base(msg.GetMessage()), msg_{msg} {}
197 const Message& GetServerMessage()
const {
return msg_; }
199 Message::Severity GetSeverity()
const {
return msg_.GetSeverity(); }
200 SqlState GetSqlState()
const {
return msg_.GetSqlState(); }
219 explicit ConnectionFailed(
const Dsn& dsn)
220 : ConnectionError(fmt::format(
"{} Failed to connect to PostgreSQL server",
221 DsnCutPassword(dsn))) {}
222 ConnectionFailed(
const Dsn& dsn, std::string_view message)
223 : ConnectionError(fmt::format(
"{} {}", DsnCutPassword(dsn), message)) {}
236 PoolError(std::string_view msg, std::string_view db_name)
237 : PoolError(fmt::format(
"{}, db_name={}", msg, db_name)) {}
239 PoolError(std::string_view msg)
240 : RuntimeError::RuntimeError(
241 fmt::format(
"Postgres ConnectionPool error: {}", msg)) {}
353 std::string GetSchema()
const {
return GetServerMessage().GetSchema(); }
354 std::string GetTable()
const {
return GetServerMessage().GetTable(); }
355 std::string GetConstraint()
const {
356 return GetServerMessage().GetConstraint();
601 AlreadyInTransaction()
618 ResultSetError(std::string msg)
621 void AddMsgSuffix(std::string_view str) { msg_ += str; }
623 const char* what()
const noexcept override {
return msg_.c_str(); }
632 RowIndexOutOfBounds(std::size_t index)
633 : ResultSetError(fmt::format(
"Row index {} is out of bounds", index)) {}
639 FieldIndexOutOfBounds(std::size_t index)
640 : ResultSetError(fmt::format(
"Field index {} is out of bounds", index)) {}
646 FieldNameDoesntExist(std::string_view name)
647 : ResultSetError(fmt::format(
"Field name '{}' doesn't exist", name)) {}
654 template <
typename T>
655 FieldValueIsNull(std::size_t field_index, std::string_view field_name,
657 : ResultSetError(fmt::format(
"Field #{} name `{}` C++ type `{}` value is "
658 "null, forgot `std::optional`?",
659 field_index, field_name,
660 compiler::GetTypeName<T>())) {}
668 TypeCannotBeNull(std::string_view type)
669 : ResultSetError(fmt::format(
"{} cannot be null", type)) {}
678 : ResultSetError(fmt::format(
"Buffer category '{}' doesn't match the "
679 "category of the parser '{}' for type '{}'",
680 ToString(buffer), ToString(parser), type)) {}
689 UnknownBufferCategory(std::string_view context, Oid type_oid)
691 fmt::format(
"Query {} doesn't have a parser. Type oid is {}",
693 type_oid{type_oid} {};
707 InvalidInputBufferSize(std::size_t size, std::string_view message)
709 fmt::format(
"Buffer size {} is invalid: {}", size, message)) {}
716 InvalidBinaryBuffer(
const std::string& message)
717 : ResultSetError(
"Invalid binary buffer: " + message) {}
724 InvalidTupleSizeRequested(std::size_t field_count, std::size_t tuple_size)
726 std::to_string(field_count) +
" < tuple size " +
727 std::to_string(tuple_size)) {}
734 NonSingleColumnResultSet(std::size_t actual_size,
735 const std::string& type_name,
736 const std::string& func)
738 "Parsing the row consisting of " + std::to_string(actual_size) +
739 " columns as " + type_name +
740 " is ambiguous as it can be used both for "
741 "single column type and for a row. " +
742 "Please use " + func +
"<" + type_name +
">(kRowTag) or " + func +
743 "<" + type_name +
">(kFieldTag) to resolve the ambiguity.") {}
749 explicit NonSingleRowResultSet(std::size_t actual_size)
750 : ResultSetError(fmt::format(
"A single row result set was expected. "
751 "Actual result set size is {}",
759 FieldTupleMismatch(std::size_t field_count, std::size_t tuple_size)
760 : ResultSetError(fmt::format(
761 "Invalid tuple size requested. Field count {} != tuple size {}",
762 field_count, tuple_size)) {}
777 CompositeSizeMismatch(std::size_t pg_size, std::size_t cpp_size,
778 std::string_view cpp_type)
780 fmt::format(
"Invalid composite type size. PostgreSQL type has {} "
781 "members, C++ type '{}' has {} members",
782 pg_size, cpp_type, cpp_size)) {}
789 CompositeMemberTypeMismatch(std::string_view pg_type_schema,
790 std::string_view pg_type_name,
791 std::string_view field_name, Oid pg_oid,
793 : UserTypeError(fmt::format(
794 "Type mismatch for {}.{} field {}. In database the type "
795 "oid is {}, user supplied type oid is {}",
796 pg_type_schema, pg_type_name, field_name, pg_oid, user_oid)) {}
813 :
ArrayError(
"Array dimensions don't match dimensions of C++ type") {}
818 InvalidDimensions(std::size_t expected, std::size_t actual)
819 : ArrayError(fmt::format(
"Invalid dimension size {}. Expected {}", actual,
864 InvalidEnumerationLiteral(std::string_view type_name,
865 std::string_view literal)
867 fmt::format(
"Invalid enumeration literal '{}' for enum type '{}'",
868 literal, type_name)) {}
873 template <
typename Enum>
874 explicit InvalidEnumerationValue(Enum val)
876 fmt::format(
"Invalid enumeration value '{}' for enum type '{}'",
877 USERVER_NAMESPACE::utils::UnderlyingValue(val),
878 compiler::GetTypeName<Enum>())) {}
886 UnsupportedInterval()
887 :
LogicError(
"PostgreSQL intervals containing months are not supported") {
894 BoundedRangeError(std::string_view message)
895 : LogicError(fmt::format(
896 "PostgreSQL range violates bounded range invariant: {}", message)) {
912 BitStringOverflow(std::size_t actual, std::size_t expected)
913 : BitStringError(fmt::format(
"Invalid bit container size {}. Expected {}",
914 actual, expected)) {}
920 InvalidBitStringRepresentation()
921 :
BitStringError(
"Invalid bit or bit varying type representation") {}
929 InvalidDSN(std::string_view dsn, std::string_view err)
930 : RuntimeError(fmt::format(
"Invalid dsn '{}': {}", dsn, err)) {}
952 explicit IpAddressInvalidFormat(std::string_view str)
953 : IpAddressError(fmt::format(
"IP address invalid format. {}", str)) {}