Repository navigation
Say a param is invalid when its validation error has no message - #2993
Merged
Merged
Conversation
ericproulx
force-pushed
the
fix/validation-error-without-message
branch
from
September 23, 2026 06:58
8cafec0 to
8ce6fdc
Compare
Danger ReportNo issues found. |
dblock
approved these changes
Sep 23, 2026
A `Grape::Exceptions::Validation` created without a message only
translated one when given one, so Ruby's `StandardError#message` fell
back to the exception's class name, and that reached the response. A
custom validator with no `default_message_key` that calls
`validation_error!(attr_name)` answered
`number Grape::Exceptions::Validation`.
Such an error now takes a new `invalid` message ("is invalid"), with
`:invalid` as its message key.
Also covers `Validators::Base#message` called with no key, no
`:message` option and no block, which a custom validator can do and no
spec did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
fix/validation-error-without-message
branch
from
September 23, 2026 15:06
8ce6fdc to
2e8144d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A custom validator with no
default_message_keythat raises throughvalidation_error!(attr_name)renders the exception's class name as the error message:The same happens on 3.3.5 and 4.0.1.
Exceptions::Validation#initializeonly translates a message when one is given. Without one,super(message: nil)leavesStandardError#messageto fall back to the class name.Such an error now falls back to a new
invalidlocale message (is invalid), with:invalidas itsmessage_key. The response above becomesnumber is invalid.This changes what a message-less
Exceptions::Validationreports:message_keyis:invalidinstead ofnil, andmessageisis invalidinstead of the class name. The existing spec pinning the old values is updated, and UPGRADING describes the change.Found while covering
Validators::Base#message's fallback with no key, no:messageoption and no block. That branch returnsnil, and the new custom-validator spec reaches it.🤖 Generated with Claude Code