diff --git a/include/silo/query_engine/query_parse_exception.h b/include/silo/query_engine/query_parse_exception.h index e66c9b63..867f182a 100644 --- a/include/silo/query_engine/query_parse_exception.h +++ b/include/silo/query_engine/query_parse_exception.h @@ -10,8 +10,26 @@ namespace silo { -class [[maybe_unused]] QueryParseException : public std::runtime_error { +class [[maybe_unused]] QueryException : public std::runtime_error { + protected: + explicit QueryException(const std::string& error_message); + + public: + /// A short string describing the phase or similar of query + /// exception. + [[nodiscard]] virtual std::string_view duringString() const = 0; +}; + +class [[maybe_unused]] QueryParseException : public QueryException { public: [[maybe_unused]] explicit QueryParseException(const std::string& error_message); + [[nodiscard]] std::string_view duringString() const override; }; + +class [[maybe_unused]] QueryEvaluationException : public QueryException { + public: + [[maybe_unused]] explicit QueryEvaluationException(const std::string& error_message); + [[nodiscard]] std::string_view duringString() const override; +}; + } // namespace silo diff --git a/src/silo/query_engine/actions/action.cpp b/src/silo/query_engine/actions/action.cpp index 9f9025b1..e199cfbc 100644 --- a/src/silo/query_engine/actions/action.cpp +++ b/src/silo/query_engine/actions/action.cpp @@ -149,8 +149,8 @@ QueryResult Action::executeAndOrder( // query syntax but with its execution. But this will disappear // from the code base again soon. auto error = [&](const std::string_view& what) { - throw silo::QueryParseException(fmt::format( - "{} not supported for streaming endpoints when receiving more than {} rows, but got " + throw silo::QueryEvaluationException(fmt::format( + "{} not supported for streaming endpoints when returning more than {} rows, but got " "{}+", what, MATERIALIZATION_CUTOFF, diff --git a/src/silo/query_engine/query_parse_exception.cpp b/src/silo/query_engine/query_parse_exception.cpp index 12418e84..0698456e 100644 --- a/src/silo/query_engine/query_parse_exception.cpp +++ b/src/silo/query_engine/query_parse_exception.cpp @@ -4,6 +4,23 @@ #include namespace silo { -[[maybe_unused]] QueryParseException::QueryParseException(const std::string& error_message) + +QueryException::QueryException(const std::string& error_message) : std::runtime_error(error_message.c_str()) {} -} // namespace silo \ No newline at end of file + +[[maybe_unused]] QueryParseException::QueryParseException(const std::string& error_message) + : QueryException(error_message) {} + +std::string_view QueryParseException::duringString() const { + return "parsing"; +} + +[[maybe_unused]] QueryEvaluationException::QueryEvaluationException(const std::string& error_message +) + : QueryException(error_message) {} + +std::string_view QueryEvaluationException::duringString() const { + return "evaluation"; +} + +} // namespace silo diff --git a/src/silo_api/query_handler.cpp b/src/silo_api/query_handler.cpp index 89d54883..98ae1d36 100644 --- a/src/silo_api/query_handler.cpp +++ b/src/silo_api/query_handler.cpp @@ -50,9 +50,11 @@ void QueryHandler::post( ); } } - } catch (const silo::QueryParseException& ex) { + } catch (const silo::QueryException& ex) { response.setContentType("application/json"); - SPDLOG_INFO("Query is invalid: " + query + " - exception: " + ex.what()); + SPDLOG_INFO( + "Query is invalid: {} - exception during {}: {}", query, ex.duringString(), ex.what() + ); response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_BAD_REQUEST); std::ostream& out_stream = response.send(); out_stream << nlohmann::json(ErrorResponse{.error = "Bad request", .message = ex.what()});