THRIFT-3307 Raise an error when trying to serialize a union with an incorrect set_field
Client: Ruby
Patch: Joe Ennever
This closes #597
diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c
index f500d03..e3aa855 100644
--- a/lib/rb/ext/struct.c
+++ b/lib/rb/ext/struct.c
@@ -290,7 +290,7 @@
if (TYPE(value) == T_ARRAY) {
items = value;
- } else {
+ } else {
if (rb_cSet == CLASS_OF(value)) {
items = rb_funcall(value, entries_method_id, 0);
} else {
@@ -670,6 +670,10 @@
VALUE field_info = rb_hash_aref(struct_fields, field_id);
+ if(NIL_P(field_info)) {
+ rb_raise(rb_eRuntimeError, "set_field is not valid for this union!");
+ }
+
VALUE ttype_value = rb_hash_aref(field_info, type_sym);
int ttype = FIX2INT(ttype_value);