Move all query related exceptions to a single file

Reviewers: mislav.bradac, buda, florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D125
This commit is contained in:
Teon Banek 2017-03-15 14:08:58 +01:00
parent 1a6aaaed58
commit b956d0812b
13 changed files with 62 additions and 84 deletions

View File

@ -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"}});

View File

@ -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 {

View File

@ -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"

View File

@ -1,8 +0,0 @@
#pragma once
#include "utils/exceptions/stacktrace_exception.hpp"
class CppCodeGeneratorException : public StacktraceException {
public:
using StacktraceException::StacktraceException;
};

View File

@ -1,8 +0,0 @@
#pragma once
#include "utils/exceptions/stacktrace_exception.hpp"
class DecoderException : public StacktraceException {
public:
using StacktraceException::StacktraceException;
};

View File

@ -1,8 +0,0 @@
#pragma once
#include "utils/exceptions/stacktrace_exception.hpp"
class PlanCompilationException : public StacktraceException {
public:
using StacktraceException::StacktraceException;
};

View File

@ -1,8 +0,0 @@
#pragma once
#include "utils/exceptions/stacktrace_exception.hpp"
class PlanExecutionException : public StacktraceException {
public:
using StacktraceException::StacktraceException;
};

View File

@ -1,8 +0,0 @@
#pragma once
#include "utils/exceptions/stacktrace_exception.hpp"
class QueryEngineException : public StacktraceException {
public:
using StacktraceException::StacktraceException;
};

52
src/query/exceptions.hpp Normal file
View File

@ -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;
};
}

View File

@ -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();
}
}

View File

@ -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");
}

View File

@ -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")) {}

View File

@ -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");