Skip to content

Commit

Permalink
feat: improve validation error message of some actions on orderByFields
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Mar 25, 2024
1 parent 208e8b2 commit a0da5b5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/silo/query_engine/actions/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ void from_json(const nlohmann::json& json, std::unique_ptr<Action>& action) {
throw QueryParseException(expression_type + " is not a valid action");
}

CHECK_SILO_QUERY(
!json.contains("orderByFields") || json["orderByFields"].is_array(),
"orderByFields must be an array."
)
auto order_by_fields = json.contains("orderByFields")
? json["orderByFields"].get<std::vector<OrderByField>>()
: std::vector<OrderByField>();
Expand Down
2 changes: 2 additions & 0 deletions src/silo/query_engine/actions/fasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void Fasta::validateOrderByFields(const Database& database) const {
std::find(sequence_names.begin(), sequence_names.end(), field.name) !=
std::end(sequence_names),
fmt::format(
"OrderByField {} is not contained in the result of this operation. "
"The only fields returned by the Fasta action are {} and {}",
field.name,
fmt::join(sequence_names, ","),
primary_key_field
)
Expand Down
2 changes: 2 additions & 0 deletions src/silo/query_engine/actions/fasta_aligned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void FastaAligned::validateOrderByFields(const Database& database) const {
std::find(sequence_names.begin(), sequence_names.end(), field.name) !=
std::end(sequence_names),
fmt::format(
"OrderByField {} is not contained in the result of this operation. "
"The only fields returned by the FastaAligned action are {} and {}",
field.name,
fmt::join(sequence_names, ","),
primary_key_field
)
Expand Down
8 changes: 7 additions & 1 deletion src/silo/query_engine/actions/insertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <variant>
#include <vector>

#include <fmt/format.h>
#include <boost/container_hash/hash.hpp>
#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -53,7 +54,12 @@ void InsertionAggregation<SymbolType>::validateOrderByFields(const Database& /*d
result_field_names.end(),
[&](const std::string& result_field) { return result_field == field.name; }
),
"OrderByField " + field.name + " is not contained in the result of this operation."
fmt::format(
"OrderByField {} is not contained in the result of this operation. "
"Allowed values are {}.",
field.name,
fmt::join(result_field_names, ", ")
)
)
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/silo/query_engine/actions/mutations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <variant>
#include <vector>

#include <fmt/format.h>
#include <oneapi/tbb/blocked_range.h>
#include <oneapi/tbb/parallel_for.h>
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -176,7 +177,12 @@ void Mutations<SymbolType>::validateOrderByFields(const Database& /*database*/)
result_field_names.end(),
[&](const std::string& result_field) { return result_field == field.name; }
),
"OrderByField " + field.name + " is not contained in the result of this operation."
fmt::format(
"OrderByField {} is not contained in the result of this operation. "
"Allowed values are {}.",
field.name,
fmt::join(result_field_names, ", ")
)
)
}
}
Expand Down

0 comments on commit a0da5b5

Please sign in to comment.