@@ -961,8 +961,6 @@ std::vector<std::string> QueryImpl::Run(const std::uint8_t* proto_data,
961
961
void QueryImpl::CompileQuery (const descriptor_db::DescDb& desc_db,
962
962
const std::string& query,
963
963
std::optional<uint64_t > limit) {
964
- // TODO: improve error messages
965
-
966
964
visitors_.clear ();
967
965
emitter_ = nullptr ;
968
966
type_resolver_ = nullptr ;
@@ -1059,15 +1057,15 @@ const pb::Descriptor* QueryImpl::GetDesc(const descriptor_db::DescSet& desc_set,
1059
1057
std::string::size_type* query_start) {
1060
1058
std::string::size_type i = query.find (' :' , *query_start);
1061
1059
if (i == std::string::npos) {
1062
- throw BadQuery (" no protobuf name given " );
1060
+ throw BadQuery (" invalid protobuf query - expected: [<descriptor_set>:]<message_name>:<path> " );
1063
1061
}
1064
1062
std::string desc_name (query.substr (*query_start, i - *query_start));
1065
1063
*query_start = i + 1 ;
1066
1064
1067
1065
const pb::Descriptor* desc = desc_set.pool ->FindMessageTypeByName (desc_name);
1068
1066
if (desc == nullptr ) {
1069
1067
throw BadQuery (
1070
- " unknown protobuf (did you remember to give the full package name?)" );
1068
+ " unknown protobuf (did you remember to include the package name?)" );
1071
1069
}
1072
1070
return desc;
1073
1071
}
@@ -1077,11 +1075,11 @@ void QueryImpl::CompileQueryPart(const pb::Descriptor** desc,
1077
1075
const pb::EnumDescriptor** ed,
1078
1076
const std::string& part) {
1079
1077
if (*desc == nullptr ) {
1080
- throw BadQuery (" query does not refer to a known field" );
1078
+ throw BadQuery (std::string ( " query does not refer to a known field: " ) + part );
1081
1079
}
1082
1080
1083
1081
if (part.empty ()) {
1084
- throw BadQuery (" empty query part" );
1082
+ throw BadQuery (" unexpected empty query part" );
1085
1083
}
1086
1084
1087
1085
std::string::size_type bracket = part.find (' [' );
@@ -1096,7 +1094,7 @@ void QueryImpl::CompileQueryPart(const pb::Descriptor** desc,
1096
1094
char * end;
1097
1095
long l = std::strtol (part.c_str (), &end, 10 );
1098
1096
if (end != &part[field_selector_end]) {
1099
- throw BadQuery (" malformed field number in query" );
1097
+ throw BadQuery (std::string ( " invalid field number in query: " ) + part );
1100
1098
}
1101
1099
fd = (*desc)->FindFieldByNumber (static_cast <int >(l));
1102
1100
} else {
@@ -1148,7 +1146,7 @@ void QueryImpl::CompileQueryPart(const pb::Descriptor** desc,
1148
1146
}
1149
1147
1150
1148
if (keys_selector && !fd->is_map ()) {
1151
- throw BadQuery (" |keys can only be used for maps" );
1149
+ throw BadQuery (" ' |keys' can only be used on maps" );
1152
1150
}
1153
1151
1154
1152
if (fd->is_map ()) {
@@ -1211,10 +1209,10 @@ void QueryImpl::CompileQueryPart(const pb::Descriptor** desc,
1211
1209
size_t end;
1212
1210
long n = std::stol (rep_selector.c_str (), &end, 10 );
1213
1211
if (end != rep_selector.size ()) {
1214
- throw BadQuery (" expected numeric indexer" );
1212
+ throw BadQuery (std::string ( " expected numeric indexer at: " ) + rep_selector );
1215
1213
}
1216
1214
if (n < 0 || n > static_cast <long >(std::numeric_limits<int >::max ())) {
1217
- throw BadQuery (" index out of bounds" );
1215
+ throw BadQuery (std::string ( " index out of bounds: " + rep_selector) );
1218
1216
}
1219
1217
1220
1218
field_selector->SetWantedIndex (static_cast <int >(n));
0 commit comments