Skip to content

fix: do not rethrow client-safe exceptions as internal (#1194) - #1249

Open
ousamabenyounes wants to merge 1 commit into
overblog:masterfrom
ousamabenyounes:fix/issue-1194
Open

fix: do not rethrow client-safe exceptions as internal (#1194)#1249
ousamabenyounes wants to merge 1 commit into
overblog:masterfrom
ousamabenyounes:fix/issue-1194

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Documented? no
Fixed tickets #1194
License MIT

Problem

With errors_handler.rethrow_internal_exceptions enabled, ErrorHandler::treatExceptions()
rethrows every exception that is not a UserError or a UserWarning:

if ($rawException instanceof GraphQLUserError) { ...; continue; }
if ($rawException instanceof UserWarning)     { ...; continue; }

if ($throwRawException) {
    throw $rawException;
}

The option is documented as "re-throw internal exception", but a client-safe exception
such as ArgumentsValidationException (implements GraphQL\Error\ClientAware and returns
true from isClientSafe()) is not internal. It was nonetheless rethrown and bubbled
up raw instead of being formatted into the GraphQL response.

Fix

Before the rethrow, format any client-safe ClientAware exception like a user error.
Only genuinely internal (non-client-safe) exceptions are still rethrown. The default
path (rethrow_internal_exceptions = false) is unchanged: such exceptions already ended
up in the formatted errors.

Test verification (RED → GREEN)

New test wraps an ArgumentsValidationException and calls handleErrors($result, true).

RED — on the unmodified branch (fix reverted, test only), the exception is rethrown:

There was 1 error:
1) ...testMaskErrorWithWrappedClientSafeExceptionAndThrowExceptionSetToTrue
Overblog\GraphQLBundle\Validator\Exception\ArgumentsValidationException: validation
ERRORS! Tests: 16, Errors: 1.

GREEN — with the fix, it is formatted into the response:

OK (16 tests, 23 assertions)

Full suite is iso-baseline (the 5 pre-existing GraphDumpSchemaCommandTest failures on
master are unrelated and unchanged): Tests: 713, Failures: 5.

With rethrow_internal_exceptions enabled, ErrorHandler::treatExceptions()
rethrew any exception that was not a UserError or UserWarning. A client-safe
exception such as ArgumentsValidationException (implements ClientAware with
isClientSafe() === true) is not internal, yet it bubbled up raw instead of
being formatted into the response.

Format client-safe ClientAware exceptions like a user error instead of
rethrowing them; only genuinely internal (non-client-safe) exceptions are
still rethrown.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant