fix: trim long strings in minLength and maxLength error messages and display the string length - #15571
Merged
Conversation
…display the string length Fix #15550
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the error messages for string length validation by trimming very long strings and displaying the actual string length. The change addresses issue #15550 where long strings in validation error messages could be problematic for readability.
- Updated error message format to include string length for minLength and maxLength validators
- Added logic to trim strings longer than 30 characters in error messages
- Added test coverage for the new error message format with string length
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/error/messages.js | Updated minlength and maxlength error message templates to include {LENGTH} placeholder |
| lib/schemaType.js | Added logic to set length property and trim long strings in validator properties for both sync and async validation |
| test/errors.validation.test.js | Added test case to verify custom error messages can use the new {LENGTH} placeholder |
| test/model.test.js | Updated existing test expectation to match new error message format with length |
hasezoey
approved these changes
Aug 5, 2025
hasezoey
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, maybe add a test to know that >30 characters is actually shortened?
Closed
2 tasks
pull Bot
pushed a commit
to edisplay/mongoose
that referenced
this pull request
May 14, 2026
…rim to 30 chars for maxlength validator Fix Automattic#16236 Re: Automattic#15550 Re: Automattic#15571
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.
Fix #15550
Summary
minLength and maxLength validators currently display the full string output, which can be problematic in the case of very long strings. This PR trims the output if more than 30 chars, and also displays the length of the string.
Examples