Skip to content

Wrap Rack parameter parsing errors in Grape::Exceptions::RequestError#2670

Merged
dblock merged 1 commit intomasterfrom
rack_request_error
Apr 6, 2026
Merged

Wrap Rack parameter parsing errors in Grape::Exceptions::RequestError#2670
dblock merged 1 commit intomasterfrom
rack_request_error

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

@ericproulx ericproulx commented Apr 3, 2026

Closes #2668

Summary

Replaces five specific Rack-related exception classes with a single Grape::Exceptions::RequestError that forwards the Rack exception's own message directly, removing Grape's translated messages for these cases.

Changes

New: Grape::Exceptions::RequestError

A lightweight wrapper that takes any exception and an optional status: (default 400), forwarding the exception's message as-is.

Removed exception classes

Removed Was raised for
Grape::Exceptions::EmptyMessageBody EOFError
Grape::Exceptions::TooManyMultipartFiles Rack::Multipart::MultipartPartLimitError/TotalPartLimitError
Grape::Exceptions::TooDeepParameters Rack::QueryParser::ParamsTooDeepError
Grape::Exceptions::ConflictingTypes Rack::Utils::ParameterTypeError
Grape::Exceptions::InvalidParameters Rack::Utils::InvalidParameterError

Grape::RACK_ERRORS constant

Centralises the list of rescuable Rack exceptions. On Rack 3, Rack::BadRequest is a marker module included by all bad-request exception classes — a single rescue entry covers them all. On Rack 2, each class is listed individually.

# Rack 3
RACK_ERRORS = [EOFError, Rack::BadRequest]

# Rack 2
RACK_ERRORS = [EOFError, Rack::Multipart::MultipartPartLimitError, ...]

Grape::RACK_ERRORS is also used in Grape::Middleware::Base#query_params for consistent handling.

Breaking changes

  • The five removed exception classes no longer exist. Rescue Grape::Exceptions::RequestError instead.
  • Error messages for these cases now come directly from Rack rather than Grape's locale file. The corresponding translation keys have been removed from en.yml.

See UPGRADING.md for migration instructions.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the rack_request_error branch 3 times, most recently from 198e7ae to a815bc3 Compare April 3, 2026 16:46
Copy link
Copy Markdown
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Let's also add CI for the newer Rack version explicitly (vs. latest)?

Replace five specific exception classes (EmptyMessageBody, TooManyMultipartFiles,
TooDeepParameters, ConflictingTypes, InvalidParameters) with a single
Grape::Exceptions::RequestError that forwards the Rack exception message directly.

On Rack 3.1.0, a single `rescue Rack::BadRequest` covers all bad-request errors via
the marker module. Before, each exception class is listed explicitly in
Grape::RACK_ERRORS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the rack_request_error branch from a815bc3 to 08c9253 Compare April 5, 2026 21:43
@ericproulx ericproulx requested a review from dblock April 5, 2026 21:59
@dblock dblock merged commit 03e6d05 into master Apr 6, 2026
79 checks passed
@dblock dblock deleted the rack_request_error branch April 6, 2026 01:35
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.

Grape is failing on latest Rack releases.

3 participants