diff options
author | Erik Benoist <erik@reverb.com> | 2018-06-26 22:24:24 -0500 |
---|---|---|
committer | Paul Yang <TeBoring@users.noreply.github.com> | 2018-06-26 20:24:24 -0700 |
commit | 74f8e24232e0d67ab79419130b5bf3a5a875593d (patch) | |
tree | fb07e3941d100639c205b8afdd9b0660703ff534 /ruby/ext/google/protobuf_c/defs.c | |
parent | ed00fbbad100fccb042ec671b50d89145d1885c9 (diff) |
Adds a base class for all explicitly raised TypeErrors (#4255)
* This allows for ruby code to catch and handle Protobuf
TypeErrors separately from the standard Ruby TypeError
* Maintains backwards compatibility by having the new
Google::Protobuf::TypeError inherit from the base
TypeError. Any code that was catching TypeError should
continue to work.
Diffstat (limited to 'ruby/ext/google/protobuf_c/defs.c')
-rw-r--r-- | ruby/ext/google/protobuf_c/defs.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/ruby/ext/google/protobuf_c/defs.c b/ruby/ext/google/protobuf_c/defs.c index d9d2ebac..9fe04503 100644 --- a/ruby/ext/google/protobuf_c/defs.c +++ b/ruby/ext/google/protobuf_c/defs.c @@ -812,7 +812,7 @@ VALUE FieldDescriptor_submsg_name_set(VALUE _self, VALUE value) { upb_fielddef* mut_def = check_field_notfrozen(self->fielddef); const char* str = get_str(value); if (!upb_fielddef_hassubdef(self->fielddef)) { - rb_raise(rb_eTypeError, "FieldDescriptor does not have subdef."); + rb_raise(cTypeError, "FieldDescriptor does not have subdef."); } CHECK_UPB(upb_fielddef_setsubdefname(mut_def, str, &status), "Error setting submessage name"); @@ -854,7 +854,7 @@ VALUE FieldDescriptor_get(VALUE _self, VALUE msg_rb) { MessageHeader* msg; TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); if (msg->descriptor->msgdef != upb_fielddef_containingtype(self->fielddef)) { - rb_raise(rb_eTypeError, "get method called on wrong message type"); + rb_raise(cTypeError, "get method called on wrong message type"); } return layout_get(msg->descriptor->layout, Message_data(msg), self->fielddef); } @@ -872,7 +872,7 @@ VALUE FieldDescriptor_set(VALUE _self, VALUE msg_rb, VALUE value) { MessageHeader* msg; TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg); if (msg->descriptor->msgdef != upb_fielddef_containingtype(self->fielddef)) { - rb_raise(rb_eTypeError, "set method called on wrong message type"); + rb_raise(cTypeError, "set method called on wrong message type"); } layout_set(msg->descriptor->layout, Message_data(msg), self->fielddef, value); return Qnil; @@ -1713,7 +1713,7 @@ static void validate_msgdef(const upb_msgdef* msgdef) { upb_msg_field_next(&it)) { const upb_fielddef* field = upb_msg_iter_field(&it); if (upb_fielddef_label(field) == UPB_LABEL_REQUIRED) { - rb_raise(rb_eTypeError, "Required fields are unsupported in proto3."); + rb_raise(cTypeError, "Required fields are unsupported in proto3."); } } } @@ -1723,7 +1723,7 @@ static void validate_enumdef(const upb_enumdef* enumdef) { // value.) const char* lookup = upb_enumdef_iton(enumdef, 0); if (lookup == NULL) { - rb_raise(rb_eTypeError, + rb_raise(cTypeError, "Enum definition does not contain a value for '0'."); } } |