ruby-grape / ruby-grape/grape

NoMethodError: undefined method `serializable_hash' for #<Hash:0x00007fc3ef69c278> when error entity has root

Open
#1,870 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Hello.
I try to add error root for errors.

class API::Error < Grape::Entity
  root 'errors', 'error'
  expose :code
  expose :message
end
error!({ message: "Some error", code: 123, with: API::Error }, 400)

When error entity has root element, I have error:

NoMethodError: undefined method `serializable_hash' for #<Hash:0x00007fc3ef69c278>
	/Users/nikolay/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/grape-1.1.0/lib/grape/error_formatter/base.rb:29:in `present'

Because Grape::Entity#represent method can return entity or hash, but
Grape::ErrorFormatter::Base#present
is not ready for this result, and called to serializable_hash whatever the result.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/grape/error_formatter/base.rb:29 and compare its present handling with Grape::Entity#represent in grape-entity/lib/grape_entity/entity.rb. Reproduce the reported error! call using an entity with a root, then trace whether the result is an entity or Hash. Done means the rooted error formats without NoMethodError and preserves the expected error response.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.