Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify which attribute is missing on which Entity #105

Merged
merged 1 commit into from
Jan 15, 2015
Merged

Specify which attribute is missing on which Entity #105

merged 1 commit into from
Jan 15, 2015

Conversation

jhollinger
Copy link
Contributor

In the latest release, the ArgumentError resulting when an Entity exposes a non-existing attribute (due to typos, merges, pending database migrations, etc.) gives no context as to which attribute is missing, or even which Entity is to blame (including in the backtrace). In master I notice it now gives a NoMethodError. That's arguably an improvement, but it also tends to even further obscure that grape-entity has anything to do with the error.

In short, finding the Entity and attribute responsible for these errors is often difficult and tedious, especially in large codebases. I think a simple change to the exception message will make them much easier to find and fix. Something along the lines of NoMethodError: Entities::V1::Session missing attribute 'foo' on #<User:0x007f787ed1c7b8>.

Message in 0.4.4

ArgumentError: ArgumentError
    /home/jhollinger/.gem/ruby/2.1.0/gems/grape-entity-0.4.4/lib/grape_entity/entity.rb:557:in `delegate_attribute'
    ...

Message in master

NoMethodError: undefined method `foo' for #<User:0x007f9b0d22b2a8>
    /home/jhollinger/.gem/ruby/2.1.0/gems/activemodel-4.1.8/lib/active_model/attribute_methods.rb:435:in `method_missing'
    ....

Example proposed message

NoMethodError: Entities::V1::Session missing attribute `foo' on #<User:0x007f787ed1c7b8>
    /home/jhollinger/.gem/ruby/2.1.0/gems/grape-entity-0.4.4/lib/grape_entity/entity.rb:560:in `rescue in delegate_attribute'
    ...

@dblock
Copy link
Member

dblock commented Jan 15, 2015

Perfect, merging, thx.

dblock added a commit that referenced this pull request Jan 15, 2015
Specify which attribute is missing on which Entity
@dblock dblock merged commit 471dc4c into ruby-grape:master Jan 15, 2015
@swistaczek
Copy link

👍 great one @jhollinger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants