From: tho Date: Wed, 24 Aug 2011 13:38:30 +0000 (+0000) Subject: Packets/80221Bundle: enhanced error message in MIH message validation (once again) X-Git-Url: http://g0dil.de/git?p=senf.git;a=commitdiff_plain;h=90692e78469c816d222d235bbcc041750dcbdccb Packets/80221Bundle: enhanced error message in MIH message validation (once again) git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1808 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80221Bundle/MIHMessageRegistry.ct b/senf/Packets/80221Bundle/MIHMessageRegistry.ct index 5e7b4e2..b259ecf 100644 --- a/senf/Packets/80221Bundle/MIHMessageRegistry.ct +++ b/senf/Packets/80221Bundle/MIHMessageRegistry.ct @@ -53,7 +53,9 @@ prefix_ void senf::detail::MIHMessageRegistryEntry::validate(se const { if (! message.is()) - throw InvalidMIHPacketException("invalid packet chain"); + throw InvalidMIHPacketException("invalid packet chain: ") + << (message.valid() ? message.typeId().prettyName() : "invalid packet") + << " != " << prettyName(typeid(MIHPacket)); MIHPacket::type::validate(message.as()); } diff --git a/senf/Packets/80221Bundle/MIHMessageRegistry.test.cc b/senf/Packets/80221Bundle/MIHMessageRegistry.test.cc index 2ff8314..337228e 100644 --- a/senf/Packets/80221Bundle/MIHMessageRegistry.test.cc +++ b/senf/Packets/80221Bundle/MIHMessageRegistry.test.cc @@ -120,6 +120,8 @@ SENF_AUTO_UNIT_TEST(MIHMessageRegistry_validate) test::TestMessagePacket testMessage (test::TestMessagePacket::createAfter(mihPacket)); mihPacket.finalizeAll(); BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket)); + mihPacket->messageId() = test::ValidatedTestMessagePacketType::MESSAGE_ID; + BOOST_CHECK_THROW( MIHPacketType::validate( mihPacket), InvalidMIHPacketException); } { test::ValidatedTestMessagePacket testMessage (test::ValidatedTestMessagePacket::createAfter(mihPacket)); diff --git a/senf/Packets/80221Bundle/TLVParser.cc b/senf/Packets/80221Bundle/TLVParser.cc index d677de8..7474b0b 100644 --- a/senf/Packets/80221Bundle/TLVParser.cc +++ b/senf/Packets/80221Bundle/TLVParser.cc @@ -63,7 +63,8 @@ prefix_ void senf::MIHBaseTLVParser::validateTypeLength(boost::uint8_t expectedT { validateType( expectedType); if (length() != expectedLength) - throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << unsigned(type()); + throw InvalidMIHPacketException("invalid length in TLV.") << " Type: " << unsigned(type()) + << ", expected length: " << expectedLength << " got " << length(); } //-///////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/senf/Packets/PacketData.hh b/senf/Packets/PacketData.hh index dfdd455..cbcad49 100644 --- a/senf/Packets/PacketData.hh +++ b/senf/Packets/PacketData.hh @@ -166,7 +166,10 @@ namespace senf { byte. If the packet has been implemented correctly, this signals a malformed packet. */ struct TruncatedPacketException : public senf::Exception - { TruncatedPacketException() : senf::Exception("truncated packet") {} }; + { + TruncatedPacketException(std::string const & description = "") + : senf::Exception("truncated packet") { append( description); } + }; }