diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-05 14:14:32 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2014-12-05 14:14:32 +0100 |
commit | bf59bc2edbb1f3f4d12bfbd8ed2663fbbb1900c0 (patch) | |
tree | 30d1fcfaf43045904883f1f068be6347487eedb4 | |
parent | ddbea4164e126739f39658627c04e7e23b71e090 (diff) |
removed fatal flag from LoggableException, added constructor capable of using a PosType
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/core/Exceptions.cpp | 2 | ||||
-rw-r--r-- | src/core/Exceptions.hpp | 45 | ||||
-rw-r--r-- | src/core/Logger.hpp | 29 | ||||
-rw-r--r-- | src/plugins/css/CSSParser.cpp | 37 | ||||
-rw-r--r-- | src/plugins/xml/XmlParser.cpp | 3 | ||||
-rw-r--r-- | test/core/LoggerTest.cpp | 4 | ||||
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 1 |
8 files changed, 37 insertions, 85 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e9cc0da..98b7acb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,7 @@ IF(TEST) # Register the unit tests ADD_TEST(ousia_test_core ousia_test_core) ADD_TEST(ousia_test_xml ousia_test_xml) + ADD_TEST(ousia_test_css ousia_test_css) # ADD_TEST(ousia_test_mozjs ousia_test_mozjs) ENDIF() diff --git a/src/core/Exceptions.cpp b/src/core/Exceptions.cpp index 206f5b2..d064f35 100644 --- a/src/core/Exceptions.cpp +++ b/src/core/Exceptions.cpp @@ -26,7 +26,7 @@ namespace ousia { std::string LoggableException::formatMessage(const std::string &msg, const std::string &file, - bool fatal, int line, int column) + int line, int column) { std::stringstream ss; ss << "error "; diff --git a/src/core/Exceptions.hpp b/src/core/Exceptions.hpp index a5d50d5..00d6106 100644 --- a/src/core/Exceptions.hpp +++ b/src/core/Exceptions.hpp @@ -81,8 +81,8 @@ private: * reported to the runtime environment. */ static std::string formatMessage(const std::string &msg, - const std::string &file, bool fatal, - int line, int column); + const std::string &file, int line, + int column); public: /** @@ -96,12 +96,6 @@ public: const std::string file; /** - * If set to true, the exception should not be handled as recoverable error - * but as "fatal" error. - */ - const bool fatal; - - /** * Line at which the exception occured. Negative values are ignored. */ const int line; @@ -118,14 +112,12 @@ public: * @param file provides the context the message refers to. May be empty. * @param line is the line in the above file the message refers to. * @param column is the column in the above file the message refers to. - * @param fatal shoudl be set to true if the error is non-recoverable. */ - LoggableException(std::string msg, std::string file, bool fatal, - int line = -1, int column = -1) - : OusiaException(formatMessage(msg, file, fatal, line, column)), + LoggableException(std::string msg, std::string file, int line = -1, + int column = -1) + : OusiaException(formatMessage(msg, file, line, column)), msg(std::move(msg)), file(std::move(file)), - fatal(fatal), line(line), column(column) { @@ -135,49 +127,30 @@ public: * Constructor of the LoggableException class with empty file. * * @param msg contains the error message. - * @param fatal should be set to true if the error is non-recoverable. * @param line is the line in the above file the message refers to. * @param column is the column in the above file the message refers to. */ - LoggableException(std::string msg, bool fatal, int line = -1, int column = -1) - : OusiaException(formatMessage(msg, "", fatal, line, column)), + LoggableException(std::string msg, int line = -1, int column = -1) + : OusiaException(formatMessage(msg, "", line, column)), msg(std::move(msg)), - fatal(fatal), line(line), column(column) { } /** - * Constructor of the LoggableException class with empty file. - * - * @param msg contains the error message. - * @param fatal should be set to true if the error is non-recoverable. - */ - LoggableException(std::string msg, bool fatal) - : OusiaException(formatMessage(msg, "", fatal, -1, -1)), - msg(std::move(msg)), - fatal(fatal), - line(-1), - column(-1) - { - } - - /** * Constructor of the LoggableException class with empty file and an * position object. * * @param msg is the actual log message. * @param pos is a const reference to a variable which provides position * information. - * @param fatal should be set to true if the error is non-recoverable. */ template <class PosType> - LoggableException(std::string msg, bool fatal, const PosType &pos) + LoggableException(std::string msg, const PosType &pos) : OusiaException( - formatMessage(msg, "", fatal, pos.getLine(), pos.getColumn())), + formatMessage(msg, "", pos.getLine(), pos.getColumn())), msg(std::move(msg)), - fatal(fatal), line(pos.getLine()), column(pos.getColumn()) { diff --git a/src/core/Logger.hpp b/src/core/Logger.hpp index fd7bb08..e6b97f4 100644 --- a/src/core/Logger.hpp +++ b/src/core/Logger.hpp @@ -251,7 +251,7 @@ public: * @tparam PosType is the actual type of pos and must implement a getLine * and getColumn function. */ - template<class PosType> + template <class PosType> void logAt(Severity severity, const std::string &msg, const PosType &pos) { log(severity, msg, pos.getLine(), pos.getColumn()); @@ -264,7 +264,7 @@ public: */ void log(const LoggableException &ex) { - log(ex.fatal ? Severity::FATAL_ERROR : Severity::ERROR, ex.msg, + log(Severity::ERROR, ex.msg, ex.file.empty() ? currentFilename() : ex.file, ex.line, ex.column); } @@ -279,7 +279,8 @@ public: * @param column is the column in the above file at which the error occured. * Ignored if negative. */ - void debug(const std::string &msg, const std::string &file, int line = -1, int column = -1) + void debug(const std::string &msg, const std::string &file, int line = -1, + int column = -1) { log(Severity::DEBUG, msg, file, line, column); } @@ -308,7 +309,7 @@ public: * @param pos is a const reference to a variable which provides position * information. */ - template<class PosType> + template <class PosType> void debugAt(const std::string &msg, const PosType &pos) { debug(msg, pos.getLine(), pos.getColumn()); @@ -325,7 +326,8 @@ public: * @param column is the column in the above file at which the error occured. * Ignored if negative. */ - void note(const std::string &msg, const std::string &file, int line = -1, int column = -1) + void note(const std::string &msg, const std::string &file, int line = -1, + int column = -1) { log(Severity::NOTE, msg, file, line, column); } @@ -353,7 +355,7 @@ public: * @param pos is a const reference to a variable which provides position * information. */ - template<class PosType> + template <class PosType> void noteAt(const std::string &msg, const PosType &pos) { note(msg, pos.getLine(), pos.getColumn()); @@ -370,7 +372,8 @@ public: * @param column is the column in the above file at which the error occured. * Ignored if negative. */ - void warning(const std::string &msg, const std::string &file, int line = -1, int column = -1) + void warning(const std::string &msg, const std::string &file, int line = -1, + int column = -1) { log(Severity::WARNING, msg, file, line, column); } @@ -383,7 +386,7 @@ public: * @param pos is a const reference to a variable which provides position * information. */ - template<class PosType> + template <class PosType> void warningAt(const std::string &msg, const PosType &pos) { warning(msg, pos.getLine(), pos.getColumn()); @@ -415,7 +418,8 @@ public: * @param column is the column in the above file at which the error occured. * Ignored if negative. */ - void error(const std::string &msg, const std::string &file, int line = -1, int column = -1) + void error(const std::string &msg, const std::string &file, int line = -1, + int column = -1) { log(Severity::ERROR, msg, file, line, column); } @@ -443,7 +447,7 @@ public: * @param pos is a const reference to a variable which provides position * information. */ - template<class PosType> + template <class PosType> void errorAt(const std::string &msg, const PosType &pos) { error(msg, pos.getLine(), pos.getColumn()); @@ -460,7 +464,8 @@ public: * @param column is the column in the above file at which the error occured. * Ignored if negative. */ - void fatalError(const std::string &msg, const std::string &file, int line = -1, int column = -1) + void fatalError(const std::string &msg, const std::string &file, + int line = -1, int column = -1) { log(Severity::FATAL_ERROR, msg, file, line, column); } @@ -488,7 +493,7 @@ public: * @param pos is a const reference to a variable which provides position * information. */ - template<class PosType> + template <class PosType> void fatalErrorAt(const std::string &msg, const PosType &pos) { fatalError(msg, pos.getLine(), pos.getColumn()); diff --git a/src/plugins/css/CSSParser.cpp b/src/plugins/css/CSSParser.cpp index 22752dd..6653d9e 100644 --- a/src/plugins/css/CSSParser.cpp +++ b/src/plugins/css/CSSParser.cpp @@ -125,18 +125,9 @@ void CSSParser::parseSelectors(Rooted<SelectorNode> root, case 2: // as the parseSelector is supposed to parse only a SelectorPath // there should not be more than one leaf. -<<<<<<< HEAD:application/src/core/CSSParser.cpp - throw LoggableException{ - "Internal Error: More than one leaf in SelectorPath!", true, - tokenizer.getInput()}; -======= throw ParserException{ - "Internal Error: More than one leaf in SelectorPath!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; ->>>>>>> 8a4203636865b6edc380b731c68d3483ca110a27:application/src/plugins/css/CSSParser.cpp + "Internal Error: More than one leaf in SelectorPath!", + tokenizer.getInput()}; } // if we find a comma, we can proceed parsing selectors. Token t; @@ -298,27 +289,11 @@ bool CSSParser::expect(int expectedType, CodeTokenizer &tokenizer, Token &t, if (end || t.tokenId != expectedType) { if (force) { if (end) { -<<<<<<< HEAD:application/src/core/CSSParser.cpp - throw LoggableException{"Unexpected end of file!", true, - tokenizer.getInput()}; - } else { - throw LoggableException{"Unexpected token!", true, - tokenizer.getInput()}; -======= - throw ParserException{ - "Unexpected end of file!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; + throw ParserException{"Unexpected end of file!", + tokenizer.getInput()}; } else { - throw ParserException{ - "Unexpected token!", "", - // TODO: Line handling? - // tokenizer.getInput().getLine(), - // tokenizer.getInput().getColumn() - }; ->>>>>>> 8a4203636865b6edc380b731c68d3483ca110a27:application/src/plugins/css/CSSParser.cpp + throw ParserException{"Unexpected token!", + tokenizer.getInput()}; } } else { tokenizer.resetPeek(); diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp index afc7f14..ce2857e 100644 --- a/src/plugins/xml/XmlParser.cpp +++ b/src/plugins/xml/XmlParser.cpp @@ -208,8 +208,7 @@ Rooted<Node> XmlParser::parse(std::istream &is, ParserContext &ctx) const int column = XML_GetCurrentColumnNumber(&p); const XML_Error code = XML_GetErrorCode(&p); const std::string msg = std::string{XML_ErrorString(code)}; - throw ParserException{"XML Syntax Error: " + msg, line, column, - false}; + throw ParserException{"XML Syntax Error: " + msg, line, column}; } // Abort once there are no more bytes in the stream diff --git a/test/core/LoggerTest.cpp b/test/core/LoggerTest.cpp index 0c333ce..abb76de 100644 --- a/test/core/LoggerTest.cpp +++ b/test/core/LoggerTest.cpp @@ -52,14 +52,14 @@ TEST(TerminalLogger, log) logger.fatalError("This is a test fatal error!", 10, 20); try { - throw LoggableException{"A fatal exception", true}; + throw LoggableException{"An exception"}; } catch (const LoggableException &ex) { logger.log(ex); } try { - throw LoggableException{"A fatal exception at position", true, Pos(10, 20)}; + throw LoggableException{"An exception at position", Pos(10, 20)}; } catch (const LoggableException &ex) { logger.log(ex); diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index ecc9438..7dc8c24 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -37,7 +37,6 @@ TEST(XmlParser, mismatchedTagException) } catch (ParserException ex) { ASSERT_EQ(2, ex.line); - ASSERT_FALSE(ex.fatal); hadException = true; } ASSERT_TRUE(hadException); |