NoMethodError: undefined method `serializable_hash' for #<Hash:0x00007fc3ef69c278> when error entity has root
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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