ruby-grape / grape-entity

An API focused facade that sits on top of an object model.
MIT License
715 stars 153 forks source link

Frozen/Deadlocked Ruby thread instead of NoMethodError #357

Open danielricecodes opened 3 years ago

danielricecodes commented 3 years ago

I am not sure if this is a known issue or not, but when yielding to a block w/ 2 arguments (e.g. arity = 2) its possible to freeze your app / test code. The following coding mistake should have resulted in a NoMethodError. Instead, Ruby freezes and I have to kill -9 the thread.

The following will freeze my app in its tracks. It should throw a NoMethodError.

module Entities
  class Invoice < Grape::Entity
    expose :id
    expose(:foo) do |object, options|
      bar.to_s
    end
  end
end

The only mistake above was not referencing object first.

module Entities
  class Invoice < Grape::Entity
    expose :id
    expose(:foo) do |object, options|
      object.bar.to_s
    end
  end
end

I'm happy to try to fix this - but first I'm asking if anyone else has noticed this or maybe there is already a PR for something similar?

Versions

Ruby 2.7.3 Rails 6.1 grape (1.5.3) grape-entity (0.9.0)

LeFnord commented 2 years ago

never heared about it, but it sounds reasonable …