Packets/80221Bundle: enhanced error message in MIH message validation (once again)
tho [Wed, 24 Aug 2011 13:38:30 +0000 (13:38 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1808 270642c3-0616-0410-b53a-bc976706d245

senf/Packets/80221Bundle/MIHMessageRegistry.ct
senf/Packets/80221Bundle/MIHMessageRegistry.test.cc
senf/Packets/80221Bundle/TLVParser.cc
senf/Packets/PacketData.hh

index 5e7b4e2..b259ecf 100644 (file)
@@ -53,7 +53,9 @@ prefix_ void senf::detail::MIHMessageRegistryEntry<MIHPacket, true>::validate(se
     const
 {
     if (! message.is<MIHPacket>())
-        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<MIHPacket>());
 }
 
index 2ff8314..337228e 100644 (file)
@@ -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));
index d677de8..7474b0b 100644 (file)
@@ -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();
 }
 
 //-/////////////////////////////////////////////////////////////////////////////////////////////////
index dfdd455..cbcad49 100644 (file)
@@ -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); }
+    };
 
 }