Exception thrown in error formatter in 0.9.0
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
With grape 0.9.0, submitting e.g. invalid JSON, or raising an exception in my own code (when using rescue_from in the Grape API class), Grape fails to format the error and raises a new exception:
12:05:31 web.1 | NoMethodError (undefined method `request_method' for nil:NilClass):
12:05:31 web.1 | grape (0.9.0) lib/grape/dsl/inside_route.rb:96:in `status'
12:05:31 web.1 | grape (0.9.0) lib/grape/error_formatter/base.rb:43:in `block in present'
12:05:31 web.1 | grape (0.9.0) lib/grape/error_formatter/base.rb:42:in `each'
12:05:31 web.1 | grape (0.9.0) lib/grape/error_formatter/base.rb:42:in `find'
12:05:31 web.1 | grape (0.9.0) lib/grape/error_formatter/base.rb:42:in `present'
12:05:31 web.1 | grape (0.9.0) lib/grape/error_formatter/json.rb:6:in `call'
12:05:31 web.1 | grape (0.9.0) lib/grape/middleware/error.rb:82:in `format_message'
12:05:31 web.1 | grape (0.9.0) lib/grape/middleware/error.rb:71:in `error_response'
12:05:31 web.1 | grape (0.9.0) lib/grape/middleware/error.rb:26:in `call!'
12:05:31 web.1 | grape (0.9.0) lib/grape/middleware/base.rb:18:in `call'
12:05:31 web.1 | rack (1.5.2) lib/rack/head.rb:11:in `call'
12:05:31 web.1 | rack (1.5.2) lib/rack/builder.rb:138:in `call'
12:05:31 web.1 | grape (0.9.0) lib/grape/endpoint.rb:172:in `call!'
12:05:31 web.1 | grape (0.9.0) lib/grape/endpoint.rb:160:in `call'
12:05:31 web.1 | rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call'
12:05:31 web.1 | rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize'
12:05:31 web.1 | rack-mount (0.8.3) lib/rack/mount/code_generation.rb:68:in `optimized_each'
12:05:31 web.1 | rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize'
12:05:31 web.1 | rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call'
12:05:31 web.1 | grape (0.9.0) lib/grape/api.rb:128:in `call'
12:05:31 web.1 | grape (0.9.0) lib/grape/api.rb:43:in `call!'
12:05:31 web.1 | grape (0.9.0) lib/grape/api.rb:39:in `call'
With Rails, the result is that the error is rendered using the default 500 handlers.
I've downgraded to 0.8.0 and no longer have this issue, so it would appear to be a regression.
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 by reproducing the invalid-JSON or rescue_from case, then inspect lib/grape/error_formatter/base.rb, lib/grape/error_formatter/json.rb, and lib/grape/middleware/error.rb around the reported stack trace. Done means the original error is formatted without a secondary NoMethodError, including when Rails falls back to its default 500 handlers.
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
- Mostly clear
- Newbie friendliness
- 35/100