Skip to content

Adapt to new Grape::Exceptions::ErrorResponse throwable - #98

Merged
samsonjs merged 1 commit into
aserafin:masterfrom
leoarnold:leoarnold/grape-3.3.0
Jul 2, 2026
Merged

Adapt to new Grape::Exceptions::ErrorResponse throwable#98
samsonjs merged 1 commit into
aserafin:masterfrom
leoarnold:leoarnold/grape-3.3.0

Conversation

@leoarnold

Copy link
Copy Markdown
Contributor

Grape v3.3.0 throws Grape::Exceptions::ErrorResponse objects instead of hashes, so we adjust accordingly while also maintaining backwards compatibility.

This case was not covered by the test suite,
so we add a matching test.

Change in the grape gem:

Grape v3.3.0 throws `Grape::Exceptions::ErrorResponse` objects
instead of hashes, so we adjust accordingly while also
maintaining backwards compatibility.

This case was not covered by the test suite,
so we add a matching test.

Change in the `grape` gem:

- [grape v3.3.0 changelog entry](https://github.com/ruby-grape/grape/blob/v3.3.0/CHANGELOG.md?plain=1#L22)
- [grape pull request](ruby-grape/grape#2693)
- [grape commit in master branch](ruby-grape/grape@c464ffa)

@samsonjs samsonjs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Looks good overall and thanks for adding a test. I have a nitpicky request but otherwise this is good to go.


def status_and_message(error)
case Gem::Version.new(Grape::VERSION)
when Gem::Requirement.new('>= 3.3.0')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that we can't name the new error class without blowing up on old versions of grape, but how about checking whether error.is_a?(Hash) instead of the explicit version check? I think that should do the trick too and then we don't have to rely on specific versions. When it's not a hash we'll try error.status and if something changes in the future it'll blow up in the same way, so I think it preserves the behaviour you have here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samsonjs Before I do that, please consider the following: I frequently post PRs for gems which need to support a wide range of versions of another gem (especially activerecord). Depending on the churn in that dependency, you might need to adapt more or less often. Example: HairTrigger.migrator

Using the case statement with Gem::Version and Gem::Requirement has proven to be the best practice here because:

  • It uses the same version comparison as Bundler, so you are sure to have the correct versions in place
  • It is concise (compared to the if-elsif-elsif-end some people like to use)
  • and most of all: The code clearly documents for posteriority which conditional branches can be deleted without loss once you drop support for older versions of the dependency. No guesswork!

So, do you really want me to remove this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for giving your perspective on this. I'm sold especially about cleanup later on after dropping support for 3.3 when we've long forgotten about this PR. Will merge it as is.

@samsonjs samsonjs left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@samsonjs
samsonjs merged commit 6fefffc into aserafin:master Jul 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants