Skip to content

Commit 208f446

Browse files
committed
Improved error messages
1 parent 2860352 commit 208f446

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

include/pgvector/pqxx.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ template <> struct string_traits<pgvector::SparseVector> {
133133

134134
int dimensions = std::stoi(std::string(text.substr(n + 2)));
135135
if (dimensions < 0) {
136-
throw conversion_error("Malformed sparsevec literal");
136+
throw conversion_error("Dimensions cannot be negative");
137137
}
138138

139139
std::vector<int> indices;
@@ -154,7 +154,7 @@ template <> struct string_traits<pgvector::SparseVector> {
154154
float value = std::stof(substr.substr(ne + 1));
155155

156156
if (index < 1) {
157-
throw conversion_error("Malformed sparsevec literal");
157+
throw conversion_error("Index out of bounds");
158158
}
159159

160160
indices.push_back(index - 1);

test/pqxx_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void test_sparsevec_from_string() {
252252
auto unused = pqxx::from_string<pgvector::SparseVector>("{}/-1");
253253
assert(false);
254254
} catch (const pqxx::conversion_error& e) {
255-
assert(std::string_view(e.what()) == "Malformed sparsevec literal");
255+
assert(std::string_view(e.what()) == "Dimensions cannot be negative");
256256
}
257257

258258
try {
@@ -273,14 +273,14 @@ void test_sparsevec_from_string() {
273273
auto unused = pqxx::from_string<pgvector::SparseVector>("{0:1}/1");
274274
assert(false);
275275
} catch (const pqxx::conversion_error& e) {
276-
assert(std::string_view(e.what()) == "Malformed sparsevec literal");
276+
assert(std::string_view(e.what()) == "Index out of bounds");
277277
}
278278

279279
try {
280280
auto unused = pqxx::from_string<pgvector::SparseVector>("{-2147483648:1}/1");
281281
assert(false);
282282
} catch (const pqxx::conversion_error& e) {
283-
assert(std::string_view(e.what()) == "Malformed sparsevec literal");
283+
assert(std::string_view(e.what()) == "Index out of bounds");
284284
}
285285

286286
try {

0 commit comments

Comments
 (0)