THRIFT-1151 - catch some serialization errors

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1137131 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/erl/src/thrift_protocol.erl b/lib/erl/src/thrift_protocol.erl
index 4c33412..95b7d1a 100644
--- a/lib/erl/src/thrift_protocol.erl
+++ b/lib/erl/src/thrift_protocol.erl
@@ -329,6 +329,12 @@
        element(1, Data) =:= StructureName ->
     write(Proto, {Module:struct_info(StructureName), Data});
 
+write(_, {{struct, {Module, StructureName}}, Data})
+  when is_atom(Module),
+       is_atom(StructureName) ->
+    error(struct_unmatched, {{provided, element(1, Data)},
+                             {expected, StructureName}});
+
 write(Proto0, {{list, Type}, Data})
   when is_list(Data) ->
     {Proto1, ok} = write(Proto0,