Skip to content

Conversation

@kpumuk
Copy link
Contributor

@kpumuk kpumuk commented Dec 15, 2025

When binary extension is not available (for example, in JRuby), Thrift::Union throws an unexpected NoMethodError instead of the intended error:

  1) Union Thrift::Union should raise for wrong set field when hash initialized and type checking is off
     Failure/Error: expect { Thrift::Serializer.new.serialize(union) }.to raise_error(RuntimeError, "set_field is not valid for this union!")

       expected RuntimeError with "set_field is not valid for this union!", got #<NoMethodError: undefined method '[]' for nil> with backtrace:
         # ./lib/thrift/union.rb:78:in 'write'
         # ./lib/thrift/serializer/serializer.rb:29:in 'serialize'
         # ./spec/union_spec.rb:54:in 'block in <main>'
         # ./spec/union_spec.rb:54:in 'block in <main>'
     # ./spec/union_spec.rb:54:in 'block in <main>'  

Corresponding extension code: https://github.com/apache/thrift/blob/master/lib/rb/ext/struct.c#L673-L675

  • Did you create an Apache Jira ticket? THRIFT-5909
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

…mplementation

When binary extension is not available (for example, in JRuby), Thrift::Union
throws an unexpected NoMethodError instead of the intended error:

  1) Union Thrift::Union should raise for wrong set field when hash initialized and type checking is off
     Failure/Error: expect { Thrift::Serializer.new.serialize(union) }.to raise_error(RuntimeError, "set_field is not valid for this union!")

       expected RuntimeError with "set_field is not valid for this union!", got #<NoMethodError: undefined method '[]' for nil> with backtrace:
         # ./lib/thrift/union.rb:78:in 'write'
         # ./lib/thrift/serializer/serializer.rb:29:in 'serialize'
         # ./spec/union_spec.rb:54:in 'block in <main>'
         # ./spec/union_spec.rb:54:in 'block in <main>'
     # ./spec/union_spec.rb:54:in 'block in <main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants