Skip to content

rescue_from :all not rescuing all exceptions #1713

Open
@Jelkster

Description

@Jelkster

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions