rescue_from :all not rescuing all exceptions
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
According to the README, grape can rescue from all exceptions with the following:
rescue_from :all
I recently stumbled across a case where the wrong method accidentally raised a NotImplementedError and caused the web request to hang as a result. I was surprised to see this because I had the rescue_from :all included in the API. I suspected that maybe NotImplementedError was not a StandardError and maybe that somehow had something to do with it. Sure enough, I found that it was a ScriptError.
I consulted the documentation again to see if I missed something, and actually saw an example of rescue_from NotImplementedError in the README. So it appeared as though it was perfectly valid at some point in time. That being said, I also saw the following message below an example: "In this case UserDefinedError must be inherited from StandardError".
After taking a look at error.rb it appears as though only StandardError will get rescued. I modified the source and replaced StandardError with Exception to see if that would resolve the issue and it did!
The last thing I did was inspect the history of the error.rb file to see if it was ever rescuing Exception before, and sure enough it was. It appears Rubocop recommended the change.
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 with lib/grape/middleware/error.rb, especially the exception handling described in the issue, and compare it with the README examples for rescue_from :all and NotImplementedError. Reproduce a request that raises NotImplementedError, then verify that rescue_from :all handles it without hanging and that the existing StandardError behavior remains covered.
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