diff --git a/src/communication/bolt/v1/states/executor.hpp b/src/communication/bolt/v1/states/executor.hpp index e97da2c5d..cac6f1fbb 100644 --- a/src/communication/bolt/v1/states/executor.hpp +++ b/src/communication/bolt/v1/states/executor.hpp @@ -56,7 +56,7 @@ State state_executor_run(RecordStream<Socket> &output_stream, BoltDecoder &decod return EXECUTOR; // TODO: RETURN success MAYBE - } catch (const frontend::opencypher::SyntaxException &e) { + } catch (const query::SyntaxException &e) { output_stream.write_failure( {{"code", "Memgraph.SyntaxException"}, {"message", "Syntax error"}}); output_stream.send(); @@ -67,7 +67,7 @@ State state_executor_run(RecordStream<Socket> &output_stream, BoltDecoder &decod // {"message", "Unsupported query"}}); // output_stream.send(); // return ERROR; - } catch (const QueryEngineException &e) { + } catch (const query::QueryEngineException &e) { output_stream.write_failure( {{"code", "Memgraph.QueryEngineException"}, {"message", "Query engine was unable to execute the query"}}); diff --git a/src/query/backend/cpp/compiler_structures.hpp b/src/query/backend/cpp/compiler_structures.hpp index 4c62b1d79..5e14d4e5f 100644 --- a/src/query/backend/cpp/compiler_structures.hpp +++ b/src/query/backend/cpp/compiler_structures.hpp @@ -2,26 +2,12 @@ #include <climits> #include <unordered_map> +#include "query/exceptions.hpp" #include "query/frontend/opencypher/generated/CypherParser.h" -#include "utils/exceptions/basic_exception.hpp" namespace backend { namespace cpp { -// TODO: Figure out what information to put in exception. -// Error reporting is tricky since we get stripped query and position of error -// in original query is not same as position of error in stripped query. Most -// correct approach would be to do semantic analysis with original query even -// for already hashed queries, but that has obvious performance issues. Other -// approach would be to report some of the semantic errors in runtime of the -// query and only report line numbers of semantic errors (not position in the -// line) if multiple line strings are not allowed by grammar. We could also -// print whole line that contains error instead of specifying line number. -class SemanticException : BasicException { - public: - SemanticException() : BasicException("") {} -}; - // enum VariableType { TYPED_VALUE, LIST, MAP, NODE, RELATIONSHIP, PATH }; struct Node { diff --git a/src/query/engine.hpp b/src/query/engine.hpp index 7626d0fe6..daf41d200 100644 --- a/src/query/engine.hpp +++ b/src/query/engine.hpp @@ -7,7 +7,7 @@ namespace fs = std::experimental::filesystem; #include "data_structures/concurrent/concurrent_map.hpp" #include "database/graph_db.hpp" #include "logging/loggable.hpp" -#include "query/exception/query_engine.hpp" +#include "query/exceptions.hpp" #include "query/frontend/opencypher/parser.hpp" #include "query/plan_compiler.hpp" #include "query/plan_interface.hpp" diff --git a/src/query/exception/cpp_code_generator.hpp b/src/query/exception/cpp_code_generator.hpp deleted file mode 100644 index b1fef2dce..000000000 --- a/src/query/exception/cpp_code_generator.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "utils/exceptions/stacktrace_exception.hpp" - -class CppCodeGeneratorException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; diff --git a/src/query/exception/decoder_exception.hpp b/src/query/exception/decoder_exception.hpp deleted file mode 100644 index ddae36d90..000000000 --- a/src/query/exception/decoder_exception.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "utils/exceptions/stacktrace_exception.hpp" - -class DecoderException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; diff --git a/src/query/exception/plan_compilation.hpp b/src/query/exception/plan_compilation.hpp deleted file mode 100644 index 3ba7d3032..000000000 --- a/src/query/exception/plan_compilation.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "utils/exceptions/stacktrace_exception.hpp" - -class PlanCompilationException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; diff --git a/src/query/exception/plan_execution.hpp b/src/query/exception/plan_execution.hpp deleted file mode 100644 index 182dbeb4c..000000000 --- a/src/query/exception/plan_execution.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "utils/exceptions/stacktrace_exception.hpp" - -class PlanExecutionException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; diff --git a/src/query/exception/query_engine.hpp b/src/query/exception/query_engine.hpp deleted file mode 100644 index a4cd1d248..000000000 --- a/src/query/exception/query_engine.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "utils/exceptions/stacktrace_exception.hpp" - -class QueryEngineException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; diff --git a/src/query/exceptions.hpp b/src/query/exceptions.hpp new file mode 100644 index 000000000..ff48a623e --- /dev/null +++ b/src/query/exceptions.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include "utils/exceptions/basic_exception.hpp" +#include "utils/exceptions/stacktrace_exception.hpp" + +namespace query { + +class SyntaxException : public BasicException { + public: + SyntaxException() : BasicException("") {} +}; + +// TODO: Figure out what information to put in exception. +// Error reporting is tricky since we get stripped query and position of error +// in original query is not same as position of error in stripped query. Most +// correct approach would be to do semantic analysis with original query even +// for already hashed queries, but that has obvious performance issues. Other +// approach would be to report some of the semantic errors in runtime of the +// query and only report line numbers of semantic errors (not position in the +// line) if multiple line strings are not allowed by grammar. We could also +// print whole line that contains error instead of specifying line number. +class SemanticException : BasicException { + public: + SemanticException() : BasicException("") {} +}; + +class CppCodeGeneratorException : public StacktraceException { + public: + using StacktraceException::StacktraceException; +}; + +class DecoderException : public StacktraceException { + public: + using StacktraceException::StacktraceException; +}; + +class PlanCompilationException : public StacktraceException { + public: + using StacktraceException::StacktraceException; +}; + +class PlanExecutionException : public StacktraceException { + public: + using StacktraceException::StacktraceException; +}; + +class QueryEngineException : public StacktraceException { + public: + using StacktraceException::StacktraceException; +}; + +} diff --git a/src/query/frontend/opencypher/parser.hpp b/src/query/frontend/opencypher/parser.hpp index 5106c5ec7..81a527938 100644 --- a/src/query/frontend/opencypher/parser.hpp +++ b/src/query/frontend/opencypher/parser.hpp @@ -3,9 +3,9 @@ #include <string> #include "antlr4-runtime.h" +#include "query/exceptions.hpp" #include "query/frontend/opencypher/generated/CypherLexer.h" #include "query/frontend/opencypher/generated/CypherParser.h" -#include "utils/exceptions/basic_exception.hpp" namespace frontend { namespace opencypher { @@ -13,11 +13,6 @@ namespace opencypher { using namespace antlropencypher; using namespace antlr4; -class SyntaxException : public BasicException { - public: - SyntaxException() : BasicException("") {} -}; - /** * Generates openCypher AST * This thing must me a class since parser.cypher() returns pointer and there is @@ -31,7 +26,7 @@ class Parser { */ Parser(const std::string query) : query_(std::move(query)) { if (parser_.getNumberOfSyntaxErrors()) { - throw SyntaxException(); + throw query::SyntaxException(); } } diff --git a/src/query/plan_compiler.hpp b/src/query/plan_compiler.hpp index 5b49a6287..a5594267c 100644 --- a/src/query/plan_compiler.hpp +++ b/src/query/plan_compiler.hpp @@ -4,7 +4,7 @@ #include "logging/default.hpp" #include "logging/loggable.hpp" -#include "query/exception/plan_compilation.hpp" +#include "query/exceptions.hpp" #include "query/plan_compiler_flags.hpp" #include "utils/string/join.hpp" @@ -51,7 +51,7 @@ class PlanCompiler : public Loggable { // if compilation has failed throw exception if (compile_status != 0) { logger.debug("FAIL: Query Code Compilation: {} -> {}", in_file, out_file); - throw PlanCompilationException( + throw query::PlanCompilationException( "Code compilation error. Generated code is not compilable or " "compilation settings are wrong"); } diff --git a/src/query/util.hpp b/src/query/util.hpp index 191bf07ff..494589099 100644 --- a/src/query/util.hpp +++ b/src/query/util.hpp @@ -6,15 +6,14 @@ #include <string> #include <experimental/filesystem> -#include <utils/exceptions/basic_exception.hpp> #include "fmt/format.h" #include "logging/default.hpp" -#include "utils/exceptions/stacktrace_exception.hpp" namespace fs = std::experimental::filesystem; #include "utils/file.hpp" #include "utils/string/file.hpp" #include "utils/string/trim.hpp" #include "utils/types/byte.hpp" +#include "query/exceptions.hpp" using std::cout; using std::endl; @@ -50,25 +49,11 @@ std::string extract_query(const fs::path &path) { throw BasicException("Unable to find query!"); } -class CodeLineFormatException : public StacktraceException { - public: - using StacktraceException::StacktraceException; -}; - template <typename... Args> std::string format(const std::string &format_str, const Args &... args) { return fmt::format(format_str, args...); } -template <typename... Args> -std::string code_line(const std::string &format_str, const Args &... args) { - try { - return "\t" + format(format_str, args...) + "\n"; - } catch (std::runtime_error &e) { - throw CodeLineFormatException(std::string(e.what()) + " " + format_str); - } -} - class CoutSocket { public: CoutSocket() : logger(logging::log->logger("Cout Socket")) {} diff --git a/tests/manual/query_engine.cpp b/tests/manual/query_engine.cpp index ed479db58..f7a233e6a 100644 --- a/tests/manual/query_engine.cpp +++ b/tests/manual/query_engine.cpp @@ -62,7 +62,7 @@ int main(int argc, char* argv[]) { query_engine.ReloadCustom(query, event.path); auto db_accessor = dbms.active(); query_engine.Run(query, *db_accessor, stream); - } catch (PlanCompilationException& e) { + } catch (query::PlanCompilationException& e) { log.info("Query compilation failed: {}", e.what()); } catch (std::exception& e) { log.info("Query execution failed: unknown reason");