macks / ruby-protobuf

Protocol Buffers for Ruby: This repository is not maintained. Please use https://github.com/ruby-protobuf/protobuf
172 stars 31 forks source link

Inspect crashes #3

Open mperham opened 14 years ago

mperham commented 14 years ago

Calling .inspect on a message crashes.

NoMethodError: undefined method `name' for #
18:13:57.917176 15969 qanat.rb:72: /home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:349:in `block in each_field'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:348:in `each'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:348:in `each_field'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:221:in `inspect'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:201:in `block in inspect'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:227:in `call'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:227:in `block in inspect'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:350:in `block in each_field'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:348:in `each'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:348:in `each_field'
/home/onespot/.bundle/ruby/1.9.1/gems/ruby_protobuf-0.4.0/lib/protobuf/message/message.rb:221:in `inspect'
mperham commented 14 years ago

to_s doesn't work either:

NoMethodError: undefined method `initialized?' for #<Protobuf::Field::FieldProxy:0x0000000182de68>
macks commented 14 years ago

I couldn't reproduce this problem. But I found suspicious codes in Message class. Please try this patch: http://gist.github.com/322461

If the patch can't fix the problem, please show me a reproduction test case.