From fa12399b1be92e3645b12787419518a53cb97dae Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 22 Sep 2016 20:44:13 +0100 Subject: Define all exceptions as ICE exceptions --- slicer/db/Jamfile.jam | 11 +++++++++++ slicer/db/exceptions.cpp | 6 ------ slicer/db/exceptions.h | 14 -------------- slicer/db/sqlExceptions.ice | 17 +++++++++++++++++ slicer/db/sqlInsertSerializer.cpp | 5 +++-- slicer/db/sqlSelectDeserializer.cpp | 7 ++----- slicer/db/sqlSelectDeserializer.h | 10 ---------- slicer/db/sqlUpdateSerializer.cpp | 5 ++--- slicer/db/sqlUpdateSerializer.h | 5 ----- slicer/db/testInsert.cpp | 2 +- slicer/db/testSelect.cpp | 3 ++- slicer/db/testUpdate.cpp | 3 ++- slicer/slicer/Jamfile.jam | 8 ++++++++ slicer/slicer/common.ice | 32 ++++++++++++++++++++++++++++++++ slicer/slicer/modelParts.cpp | 18 ------------------ slicer/slicer/modelParts.h | 21 --------------------- slicer/slicer/modelPartsTypes.impl.h | 3 ++- slicer/test/Jamfile.jam | 2 +- slicer/test/preprocessor.cpp | 8 +++++--- slicer/test/serializers.cpp | 9 +++++---- slicer/tool/Jamfile.jam | 3 +++ slicer/tool/parser.cpp | 20 +++++++++++--------- slicer/xml/Jamfile.jam | 7 +++++++ slicer/xml/serializer.cpp | 6 +----- slicer/xml/serializer.h | 5 ----- slicer/xml/testSpecifics.cpp | 1 + slicer/xml/xmlExceptions.ice | 13 +++++++++++++ 27 files changed, 129 insertions(+), 115 deletions(-) delete mode 100644 slicer/db/exceptions.cpp delete mode 100644 slicer/db/exceptions.h create mode 100644 slicer/db/sqlExceptions.ice create mode 100644 slicer/slicer/common.ice create mode 100644 slicer/xml/xmlExceptions.ice diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index 664b6b1..f73d3f8 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -6,17 +6,23 @@ lib adhocutil : : : : /usr/include/adhocutil ; lib boost_system ; lib boost_filesystem ; lib boost_utf : : boost_unit_test_framework ; +lib pthread ; +lib Ice ; lib IceUtil ; lib slicer-db : [ glob *.cpp : test*.cpp ] + [ glob *.ice ] : .. + pthread + Ice IceUtil dbppcore ../..//glibmm adhocutil ../slicer//slicer + ../slicer//slicer : : dbppcore ; @@ -28,6 +34,7 @@ run testSelect.cpp ROOT=\"$(me)\" BOOST_TEST_DYN_LINK slicer-db + slicer-db dbpp-postgresql boost_system boost_filesystem @@ -35,6 +42,7 @@ run testSelect.cpp ../test//slicer-test ../test//common ../slicer//slicer + ../slicer//slicer .. slicer.sql ../test//compilation @@ -54,6 +62,7 @@ run testInsert.cpp ../test//slicer-test ../test//common ../slicer//slicer + ../slicer//slicer .. slicer.sql ../test//compilation @@ -66,6 +75,7 @@ run testUpdate.cpp ROOT=\"$(me)\" BOOST_TEST_DYN_LINK slicer-db + slicer-db dbpp-postgresql boost_system boost_filesystem @@ -73,6 +83,7 @@ run testUpdate.cpp ../test//slicer-test ../test//common ../slicer//slicer + ../slicer//slicer .. slicer.sql ../test//compilation diff --git a/slicer/db/exceptions.cpp b/slicer/db/exceptions.cpp deleted file mode 100644 index 50099bd..0000000 --- a/slicer/db/exceptions.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "exceptions.h" - -namespace Slicer { - UnsupportedModelType::UnsupportedModelType() : std::invalid_argument("Unspported model type") { } -} - diff --git a/slicer/db/exceptions.h b/slicer/db/exceptions.h deleted file mode 100644 index 8673627..0000000 --- a/slicer/db/exceptions.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef SLICER_DB_EXCEPTIONS_H -#define SLICER_DB_EXCEPTIONS_H - -#include - -namespace Slicer { - class UnsupportedModelType : public std::invalid_argument { - public: - UnsupportedModelType(); - }; -} - -#endif - diff --git a/slicer/db/sqlExceptions.ice b/slicer/db/sqlExceptions.ice new file mode 100644 index 0000000..a392876 --- /dev/null +++ b/slicer/db/sqlExceptions.ice @@ -0,0 +1,17 @@ +#ifndef SLICER_XML +#define SLICER_XML + +#include + +module Slicer { + exception TooManyRowsReturned extends DeserializerError {}; + exception NoRowsReturned extends DeserializerError {}; + exception NoRowsFound extends SerializerError {}; + exception UnsuitableIdFieldType extends SerializerError { + string type; + }; +}; + +#endif + + diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 0ff0038..f5c4c4f 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -1,5 +1,6 @@ #include "sqlInsertSerializer.h" -#include "exceptions.h" +#include +#include #include "sqlBinder.h" #include #include @@ -65,7 +66,7 @@ namespace Slicer { } #define NonNumType(T) \ - void set(T &) const override { throw std::runtime_error("Can't store Id in " #T " type field"); } + void set(T &) const override { throw UnsuitableIdFieldType(#T); } #define NumType(T) \ void set(T & v) const override { v = boost::numeric_cast(connection->insertId()); } diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp index 7836c63..5e32f75 100644 --- a/slicer/db/sqlSelectDeserializer.cpp +++ b/slicer/db/sqlSelectDeserializer.cpp @@ -1,13 +1,10 @@ #include "sqlSelectDeserializer.h" #include "sqlSource.h" -#include "exceptions.h" +#include +#include #include namespace Slicer { - NoRowsReturned::NoRowsReturned() : std::runtime_error("No rows returned") { } - - TooManyRowsReturned::TooManyRowsReturned() : std::runtime_error("Too many rows returned") { } - SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand & c, IceUtil::Optional tc) : cmd(c), typeIdColName(tc) diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h index 3d73c94..c520090 100644 --- a/slicer/db/sqlSelectDeserializer.h +++ b/slicer/db/sqlSelectDeserializer.h @@ -6,16 +6,6 @@ #include namespace Slicer { - class NoRowsReturned : public std::runtime_error { - public: - NoRowsReturned(); - }; - - class TooManyRowsReturned : public std::runtime_error { - public: - TooManyRowsReturned(); - }; - class DLL_PUBLIC SqlSelectDeserializer : public Slicer::Deserializer { public: SqlSelectDeserializer(DB::SelectCommand &, IceUtil::Optional typeIdCol = IceUtil::Optional()); diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 65889ab..867b9fb 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -1,13 +1,12 @@ #include "sqlUpdateSerializer.h" -#include "exceptions.h" +#include +#include #include "sqlBinder.h" #include #include #include namespace Slicer { - NoRowsFound::NoRowsFound() : std::runtime_error("No rows found") { } - const std::string md_pkey = "db:pkey"; SqlUpdateSerializer::SqlUpdateSerializer(DB::Connection * const c, const std::string & t) : diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h index cbd8d65..83a5e04 100644 --- a/slicer/db/sqlUpdateSerializer.h +++ b/slicer/db/sqlUpdateSerializer.h @@ -6,11 +6,6 @@ #include namespace Slicer { - class NoRowsFound : public std::runtime_error { - public: - NoRowsFound(); - }; - class DLL_PUBLIC SqlUpdateSerializer : public Slicer::Serializer { public: typedef boost::shared_ptr ModifyPtr; diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp index e2118b8..ef37e66 100644 --- a/slicer/db/testInsert.cpp +++ b/slicer/db/testInsert.cpp @@ -7,7 +7,7 @@ #include "sqlInsertSerializer.h" #include "sqlSelectDeserializer.h" #include -#include "exceptions.h" +#include // LCOV_EXCL_START BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::DateTime); diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp index 6cade1d..c1e2121 100644 --- a/slicer/db/testSelect.cpp +++ b/slicer/db/testSelect.cpp @@ -6,7 +6,8 @@ #include #include "sqlSelectDeserializer.h" #include -#include "exceptions.h" +#include +#include class StandardMockDatabase : public PQ::Mock { public: diff --git a/slicer/db/testUpdate.cpp b/slicer/db/testUpdate.cpp index 159cb5e..1bf917e 100644 --- a/slicer/db/testUpdate.cpp +++ b/slicer/db/testUpdate.cpp @@ -8,7 +8,8 @@ #include "sqlSelectDeserializer.h" #include "sqlUpdateSerializer.h" #include -#include "exceptions.h" +#include +#include class StandardMockDatabase : public PQ::Mock { public: diff --git a/slicer/slicer/Jamfile.jam b/slicer/slicer/Jamfile.jam index 7def868..d6fc70f 100644 --- a/slicer/slicer/Jamfile.jam +++ b/slicer/slicer/Jamfile.jam @@ -1,15 +1,23 @@ +lib pthread ; +lib Ice ; lib IceUtil ; lib boost_system ; +lib boost_filesystem ; lib adhocutil : : : : /usr/include/adhocutil ; lib slicer : [ glob *.cpp ] + [ glob *.ice ] : + pthread + Ice IceUtil boost_system adhocutil .. : : .. + . boost_system + boost_filesystem ; diff --git a/slicer/slicer/common.ice b/slicer/slicer/common.ice new file mode 100644 index 0000000..5d87d0a --- /dev/null +++ b/slicer/slicer/common.ice @@ -0,0 +1,32 @@ +#ifndef SLICER +#define SLICER + +module Slicer { + exception CompilerError { + string what; + }; + exception RuntimeError { }; + exception SerializerError extends RuntimeError { }; + exception DeserializerError extends RuntimeError { }; + exception IncorrectElementName extends DeserializerError { + string name; + }; + exception UnsupportedModelType extends RuntimeError { }; + exception NoConversionFound extends RuntimeError { + string type; + }; + exception UnknownType extends DeserializerError { + string type; + }; + exception InvalidEnumerationValue extends SerializerError { + int value; + string type; + }; + exception InvalidEnumerationSymbol extends DeserializerError { + string symbol; + string type; + }; +}; + +#endif + diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 2e144fa..b53997e 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -4,24 +4,6 @@ namespace Slicer { const Metadata emptyMetadata; - IncorrectElementName::IncorrectElementName(const std::string & n) : - std::invalid_argument(n) - { - } - - UnknownType::UnknownType(const std::string & n) : - std::invalid_argument(n) - { - } - InvalidEnumerationValue::InvalidEnumerationValue(const std::string & n, const std::string & e) : - std::invalid_argument("No such value '" + n + "' in " + e) { } - - InvalidEnumerationValue::InvalidEnumerationValue(::Ice::Int n, const std::string & e) : - std::invalid_argument("Invalid value " + boost::lexical_cast(n) + " in " + e) { } - - NoConversionFound::NoConversionFound(const std::string & n) : - std::runtime_error("Could not convert to/from model for type " + n) { } - ClassNameMap * & classNameMap() { diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 3533cc7..c9a0995 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -22,27 +22,6 @@ namespace Slicer { return p.get(); } - class DLL_PUBLIC IncorrectElementName : public std::invalid_argument { - public: - IncorrectElementName(const std::string & n); - }; - - class DLL_PUBLIC UnknownType : public std::invalid_argument { - public: - UnknownType(const std::string & n); - }; - - class DLL_PUBLIC InvalidEnumerationValue : public std::invalid_argument { - public: - InvalidEnumerationValue(const std::string & n, const std::string & e); - InvalidEnumerationValue(::Ice::Int n, const std::string & e); - }; - - class DLL_PUBLIC NoConversionFound : public std::runtime_error { - public: - NoConversionFound(const std::string & n); - }; - template class TValueTarget { public: diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index d598bbf..2c9e20f 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -2,6 +2,7 @@ #define SLICER_MODELPARTSTYPES_IMPL_H #include "modelPartsTypes.h" +#include #define MODELPARTFOR(Type, ModelPartType) \ template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType(s); } \ @@ -325,7 +326,7 @@ namespace Slicer { { auto i = enumerations.right.find(val); if (i == enumerations.right.end()) { - throw InvalidEnumerationValue(val, typeid(T).name()); + throw InvalidEnumerationSymbol(val, typeid(T).name()); } return i->second; } diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index b6e2834..253ab2b 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -84,8 +84,8 @@ run serializers.cpp preprocess slicer-test common - .. ../slicer//slicer + ../slicer//slicer ../xml//slicer-xml ../json//slicer-json : diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index 3eb50f6..b715d50 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( slicer_test_ice ) BOOST_TEST_CHECKPOINT("cpp: " << cpp); fs::remove(cpp); const std::string doslice = stringbf( - "%s -I%s %s %s", + "%s -I%s --headerPrefix='\"\"' %s %s", root.parent_path() / "tool" / bjamout / "slicer", included, slice, cpp); @@ -78,11 +78,13 @@ BOOST_AUTO_TEST_CASE( slicer_test_ice ) const fs::path obj = fs::change_extension(tmp / base, ".o"); const std::string compile = stringbf( - "g++ -Os -fPIC -c -std=c++1y -fvisibility=hidden -I tmp -I /usr/include/adhocutil -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s -I %s -I %s %s -o %s", + "g++ -Os -fPIC -c -std=c++1y -fvisibility=hidden -I%s -I tmp -I /usr/include/adhocutil -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s -I %s -I %s -I %s %s -o %s", + root.parent_path() / "slicer", root / bjamout, root, included / bjamout, - root / "..", + root.parent_path(), + root.parent_path() / "slicer" / bjamout, cpp, obj); BOOST_TEST_CHECKPOINT("compile: " << compile); system(compile); diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index 8f569d8..9c4b406 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -2,8 +2,9 @@ #include #include -#include -#include +#include +#include +#include #include #include #include @@ -493,10 +494,10 @@ BOOST_AUTO_TEST_CASE( xml_streams ) BOOST_AUTO_TEST_CASE( invalid_enum ) { Slicer::DeserializerPtr jdeserializer = new Slicer::JsonFileDeserializer(root / "initial" / "invalidEnum.json"); - BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith(jdeserializer), Slicer::InvalidEnumerationValue); + BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith(jdeserializer), Slicer::InvalidEnumerationSymbol); Slicer::DeserializerPtr xdeserializer = new Slicer::XmlFileDeserializer(root / "initial" / "invalidEnum.xml"); - BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith(xdeserializer), Slicer::InvalidEnumerationValue); + BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith(xdeserializer), Slicer::InvalidEnumerationSymbol); } BOOST_AUTO_TEST_SUITE_END(); diff --git a/slicer/tool/Jamfile.jam b/slicer/tool/Jamfile.jam index d34828c..5362382 100644 --- a/slicer/tool/Jamfile.jam +++ b/slicer/tool/Jamfile.jam @@ -1,4 +1,5 @@ lib Slice ; +lib Ice ; lib IceUtil ; lib po : : boost_program_options ; lib adhocutil : : : : /usr/include/adhocutil ; @@ -9,11 +10,13 @@ lib slicer-compiler : parser.cpp : Slice + Ice IceUtil boost_system boost_filesystem adhocutil ../slicer//slicer + ../slicer//slicer .. : : .. diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index d6cb6c0..1144391 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -1,5 +1,6 @@ #include "parser.h" -#include +#include +#include #include #include #include @@ -118,7 +119,8 @@ namespace Slicer { fprintbf(cpp, "// Begin Slicer code\n\n"); fprintbf(cpp, "#include <%s>\n\n", fs::change_extension(topLevelFile.filename(), ".h").string()); - fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "modelPartsTypes.impl.h").string()); + fprintbf(cpp, "#include <%s>\n", (headerPrefix / "modelPartsTypes.impl.h").string()); + fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "common.h").string()); fprintbf(cpp, "namespace Slicer {\n"); return true; } @@ -391,7 +393,7 @@ namespace Slicer { s->scoped()); auto iname = metaDataValue("slicer:item:", s->getMetaData()); if (iname) { - fprintbf(cpp, "\tif (!name.empty() && name != \"%s\") { throw IncorrectElementName(); }\n", + fprintbf(cpp, "\tif (!name.empty() && name != \"%s\") { throw IncorrectElementName(name); }\n", *iname); } else { @@ -562,7 +564,7 @@ namespace Slicer { for (const auto & conversion : conversions) { auto split = metaDataSplit(conversion); if (split.size() < 3) { - throw std::runtime_error("conversion needs at least 3 parts type:toModelFunc:toExchangeFunc[:options]"); + throw CompilerError("conversion needs at least 3 parts type:toModelFunc:toExchangeFunc[:options]"); } for (auto & pi : {0, 1, 2}) { boost::algorithm::replace_all(split[pi], ".", "::"); @@ -582,13 +584,13 @@ namespace Slicer { Slicer::Execute() { if (cpp != NULL && !cppPath.empty()) { - throw std::runtime_error("Both file handle and path provided."); + throw CompilerError("Both file handle and path provided."); } FilePtr cppfile( cpp || cppPath.empty() ? cpp : fopen(cppPath.string(), "a"), cppPath.empty() ? fflush : fclose); if (!cppfile && !cppPath.empty()) { - throw std::runtime_error("Failed to open output file"); + throw CompilerError("Failed to open output file"); } cpp = cppfile.get(); Slicer::Slicer::Args args; @@ -601,7 +603,7 @@ namespace Slicer { FILE * cppHandle = icecpp->preprocess(false); if (cppHandle == NULL) { - throw std::runtime_error("preprocess failed"); + throw CompilerError("preprocess failed"); } Slice::UnitPtr u = Slice::Unit::createUnit(false, false, allowIcePrefix, false); @@ -609,11 +611,11 @@ namespace Slicer { int parseStatus = u->parse(slicePath.string(), cppHandle, false); if (!icecpp->close()) { - throw std::runtime_error("preprocess close failed"); + throw CompilerError("preprocess close failed"); } if (parseStatus == EXIT_FAILURE) { - throw std::runtime_error("unit parse failed"); + throw CompilerError("unit parse failed"); } u->visit(this, false); diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam index 76b97af..28e8aab 100644 --- a/slicer/xml/Jamfile.jam +++ b/slicer/xml/Jamfile.jam @@ -1,4 +1,6 @@ import testing ; +lib pthread ; +lib Ice ; lib boost_system ; lib boost_filesystem ; lib boost_utf : : boost_unit_test_framework ; @@ -7,14 +9,18 @@ lib adhocutil : : : : /usr/include/adhocutil ; lib slicer-xml : [ glob *.cpp : test*.cpp ] + [ glob *.ice ] : .. boost_system boost_filesystem + pthread + Ice IceUtil ../..//libxmlpp adhocutil ../slicer//slicer + ../slicer//slicer : : ../..//libxmlpp ; @@ -23,6 +29,7 @@ run testSpecifics.cpp : : : BOOST_TEST_DYN_LINK slicer-xml + slicer-xml boost_utf ../test//slicer-test ../test//common diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index c6c6c5f..c1e4023 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -1,4 +1,5 @@ #include "serializer.h" +#include #include #include #include @@ -19,11 +20,6 @@ namespace Slicer { const std::string md_bare = "xml:bare"; const auto defaultElementCreator = boost::bind(&xmlpp::Element::add_child, _1, _2, Glib::ustring()); - BadBooleanValue::BadBooleanValue(const Glib::ustring &) : - std::invalid_argument("Bad boolean value") - { - } - static const Glib::ustring TrueText("true"); static const Glib::ustring FalseText("false"); diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index 054b308..cdb20f5 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -6,11 +6,6 @@ #include namespace Slicer { - class BadBooleanValue : public std::invalid_argument { - public: - BadBooleanValue(const Glib::ustring &); - }; - class DLL_PUBLIC XmlSerializer : public Serializer { protected: typedef boost::function ElementCreator; diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp index 001cfb0..d20ea09 100644 --- a/slicer/xml/testSpecifics.cpp +++ b/slicer/xml/testSpecifics.cpp @@ -4,6 +4,7 @@ #include "serializer.h" #include #include +#include template T diff --git a/slicer/xml/xmlExceptions.ice b/slicer/xml/xmlExceptions.ice new file mode 100644 index 0000000..e03fbe7 --- /dev/null +++ b/slicer/xml/xmlExceptions.ice @@ -0,0 +1,13 @@ +#ifndef SLICER_XML +#define SLICER_XML + +#include + +module Slicer { + exception BadBooleanValue extends DeserializerError { + string text; + }; +}; + +#endif + -- cgit v1.2.3