Throw client-safe errors for malformed date literals - #2788
Merged
Conversation
arunarw
force-pushed
the
fix-date-literal-client-safe
branch
from
September 2, 2026 09:35
38d18ee to
f64f658
Compare
DateScalar::parseLiteral passed the Carbon exception to Error::createLocatedError, which keeps it as the error's previous. Since InvalidFormatException is not ClientAware, that marked the error as non-client-safe: the message was masked as "Internal server error" and the exception was handed to the application's error reporter. The variable path already rethrows without a previous via tryParsingDate, so the same malformed value was a client error as a variable but a server fault as a literal. Bring literals in line.
arunarw
force-pushed
the
fix-date-literal-client-safe
branch
from
September 2, 2026 12:04
f64f658 to
32e189e
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The targeted implementation preserves locations, corrects error classification, and includes appropriate shared test coverage.
Pull request overview
Makes malformed date literals client-safe so GraphQL returns useful validation errors without server-side reporting.
Changes:
- Wraps parsing failures in client-safe GraphQL errors while preserving source locations.
- Adds coverage for all four date scalar types.
- Documents the fix in the changelog.
File summaries
| File | Description |
|---|---|
src/Schema/Types/Scalars/DateScalar.php |
Makes malformed literal errors client-safe. |
tests/Unit/Schema/Types/Scalars/DateScalarTestBase.php |
Verifies client-safe errors across date scalars. |
CHANGELOG.md |
Records the corrected behavior. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
spawnia
approved these changes
Sep 2, 2026
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.
Changes
A malformed date is handled differently depending on whether it arrives as a query literal or as a variable. As a variable it is a client error. As a literal it is classified as a server fault: the message is masked as
"Internal server error"and the exception is passed to the application's error reporter.parseValue()→tryParsingDate()rethrows without a previous:parseLiteral()preserved it:Carbon\Exceptions\InvalidFormatExceptiondoes not implementClientAware, soError::__constructsetsisClientSafe = false.FormattedErrorthen masks the message, andReportingErrorHandlerforwards the exception toExceptionHandler::report().This affects
Date,DateTime,DateTimeTzandDateTimeUtc, which all inheritparseLiteralfromDateScalar.The fix throws a client-safe error while keeping
$valueNode, solocationsis unchanged:The added test lives in
DateScalarTestBase, so it covers all four scalars. It fails on all four before the change:The existing suite already covered
parseValuewith an invalid date andparseLiteralwith a non-string node, but notparseLiteralwith a malformed date string — which is why this went unnoticed.We hit this on a
Datequery argument in production: roughly 6,200 reported exceptions from one client sendingYYYY/MM/DD, each surfacing as a masked"Internal server error"rather than a usable validation message.Breaking changes
None. Malformed literals still throw an
Errorwith the same message and locations; onlyisClientSafechanges, so the error is no longer masked or reported. Valid values,parseValueandserializeare untouched.