From 285ee84d0942fbfef1a2c2b75118ccde2ac3e6c5 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Sat, 19 Oct 2024 18:56:44 +0000 Subject: [PATCH] . --- library/include/larra/serialization.hpp | 4 ++-- library/include/larra/serialization/auto.hpp | 18 +++++++----------- library/include/larra/serialization/error.hpp | 10 +++++----- tests/serialization.cpp | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/library/include/larra/serialization.hpp b/library/include/larra/serialization.hpp index c4377c2..a24e0a8 100644 --- a/library/include/larra/serialization.hpp +++ b/library/include/larra/serialization.hpp @@ -97,8 +97,8 @@ template struct Serialization : SerializationBase { [[nodiscard]] static constexpr auto Parse(xmlpp::Element* element) -> T { if(!Serialization::StartCheck(element)) { - throw serialization::SerializationError{ - std::format("[{}: {}] serialization error: [ StartCheck failed ]", Serialization::kDefaultName, nameof::nameof_full_type())}; + throw serialization::ParsingError{ + std::format("[{}: {}] parsing error: [ StartCheck failed ]", Serialization::kDefaultName, nameof::nameof_full_type())}; } return T::Parse(element); } diff --git a/library/include/larra/serialization/auto.hpp b/library/include/larra/serialization/auto.hpp index 13aa9fa..8667957 100644 --- a/library/include/larra/serialization/auto.hpp +++ b/library/include/larra/serialization/auto.hpp @@ -103,19 +103,16 @@ struct ElementSerializer { static constexpr auto Parse(xmlpp::Element* element) { auto node = element->get_first_child(Info::kName); if(!node) { - throw ElementSerializationError( - std::format("[{}: {}] serialization error: [ Not found ]", Info::kName, nameof::nameof_full_type())); + throw ElementParsingError(std::format("[{}: {}] parsing error: [ Not found ]", Info::kName, nameof::nameof_full_type())); } auto elementNode = dynamic_cast(node); if(!node) { - throw ElementSerializationError( - std::format("[{}: {}] serialization error: [ Invalid node ]", Info::kName, nameof::nameof_full_type())); + throw ElementParsingError(std::format("[{}: {}] parsing error: [ Invalid node ]", Info::kName, nameof::nameof_full_type())); } try { return ::larra::xmpp::serialization::Parse(elementNode, Tag{}); - } catch(const SerializationError& error) { - throw ElementSerializationError( - std::format("[{}: {}] serialization error: [ {} ]", Info::kName, nameof::nameof_full_type(), error.what())); + } catch(const ParsingError& error) { + throw ElementParsingError(std::format("[{}: {}] parsing error: [ {} ]", Info::kName, nameof::nameof_full_type(), error.what())); } } }; @@ -134,8 +131,7 @@ auto ParseField(xmlpp::Element* main) -> std::decay_t::type { if constexpr(std::holds_alternative(Config.Base())) { xmlpp::Attribute* node = main->get_attribute(Info::kName); if(!node) { - throw AttributeSerializationError( - std::format("Attribute [{}: {}] serialization error", Info::kName, nameof::nameof_full_type())); + throw AttributeParsingError(std::format("Attribute [{}: {}] parsing error", Info::kName, nameof::nameof_full_type())); } if constexpr(requires(std::string_view view) { Type::Parse(view); }) { return Type::Parse(node->get_value()); @@ -184,8 +180,8 @@ constexpr auto Parse(xmlpp::Element* element, Tag) -> T return utempl::Unpack(utempl::PackConstexprWrapper(), [&](auto... configs) { try { return T{impl::ParseField<*((*configs).second), FieldInfo>(element)...}; - } catch(const SerializationError& error) { - throw ElementSerializationError(std::format("[{}] serialization error: [ {} ]", nameof::nameof_full_type(), error.what())); + } catch(const ParsingError& error) { + throw ElementParsingError(std::format("[{}] parsing error: [ {} ]", nameof::nameof_full_type(), error.what())); } }); } diff --git a/library/include/larra/serialization/error.hpp b/library/include/larra/serialization/error.hpp index a3594d5..83ea97e 100644 --- a/library/include/larra/serialization/error.hpp +++ b/library/include/larra/serialization/error.hpp @@ -3,16 +3,16 @@ namespace larra::xmpp::serialization { -struct SerializationError : std::runtime_error { +struct ParsingError : std::runtime_error { using std::runtime_error::runtime_error; }; -struct AttributeSerializationError : SerializationError { - using SerializationError::SerializationError; +struct AttributeParsingError : ParsingError { + using ParsingError::ParsingError; }; -struct ElementSerializationError : SerializationError { - using SerializationError::SerializationError; +struct ElementParsingError : ParsingError { + using ParsingError::ParsingError; }; } // namespace larra::xmpp::serialization diff --git a/tests/serialization.cpp b/tests/serialization.cpp index 97f31f6..0e95574 100644 --- a/tests/serialization.cpp +++ b/tests/serialization.cpp @@ -109,7 +109,7 @@ TEST(AutoParse, Basic) { EXPECT_EQ(a.value, "Hello"sv); auto b = Serialization::Parse(doc.get_root_node()); EXPECT_EQ(b.value.value, "Hello"sv); - EXPECT_THROW(std::ignore = tests::serialization::SomeStruct2::Parse(node), serialization::SerializationError); + EXPECT_THROW(std::ignore = tests::serialization::SomeStruct2::Parse(node), serialization::ParsingError); auto node2 = node->add_child_element("some4"); node2->add_child_element("some3"); auto c = Serialization::Parse(node2);