src/Error/FormattedError.php
public static function addDebugEntries(array $formattedError, $e, $debug)
    {
        if (! $debug) {
            return $formattedError;
        }

        Utils::invariant(
            $e instanceof Exception || $e instanceof Throwable,
            'Expected exception, got %s',
            Utils::getVariableType($e)
        );

        $debug = (int) $debug;

        if ($debug & Debug::RETHROW_INTERNAL_EXCEPTIONS) {
            if (! $e instanceof Error) {
                throw $e;
            }

            if ($e->getPrevious()) {
                throw $e->getPrevious();
            }
        }

        $isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe();

        if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) {
            if ($e->getPrevious()) {
                throw $e->getPrevious();
            }
        }

        if (($debug & Debug::INCLUDE_DEBUG_MESSAGE) && $isUnsafe) {
            // Displaying debugMessage as a first entry:
            $formattedError = ['debugMessage' => $e->getMessage()] + $formattedError;
        }

        if ($debug & Debug::INCLUDE_TRACE) {
            if ($e instanceof ErrorException || $e instanceof \Error) {
                $formattedError += [
                    'file' => $e->getFile(),
                    'line' => $e->getLine(),
                ];
            }

            $isTrivial = $e instanceof Error && ! $e->getPrevious();

            if (! $isTrivial) {
                $debugging               = $e->getPrevious() ?: $e;
                $formattedError['trace'] = static::toSafeTrace($debugging);
            }
        }

        return $formattedError;
    }
public static function addDebugEntries(array $formattedError, $e, $debug)
    {
        if (! $debug) {
            return $formattedError;
        }

        Utils::invariant(
            $e instanceof Exception || $e instanceof Throwable,
            'Expected exception, got %s',
            Utils::getVariableType($e)
        );

        $debug = (int) $debug;

        if ($debug & Debug::RETHROW_INTERNAL_EXCEPTIONS) {
            if (! $e instanceof Error) {
                throw $e;
            }

            if ($e->getPrevious()) {
                throw $e->getPrevious();
            }
        }

        $isUnsafe = ! $e instanceof ClientAware || ! $e->isClientSafe();

        if (($debug & Debug::RETHROW_UNSAFE_EXCEPTIONS) && $isUnsafe) {
            if ($e->getPrevious()) {
                throw $e->getPrevious();
            }
        }

        if (($debug & Debug::INCLUDE_DEBUG_MESSAGE) && $isUnsafe) {
            // Displaying debugMessage as a first entry:
            $formattedError = ['debugMessage' => $e->getMessage()] + $formattedError;
        }

        if ($debug & Debug::INCLUDE_TRACE) {
            if ($e instanceof ErrorException || $e instanceof \Error) {
                $formattedError += [
                    'file' => $e->getFile(),
                    'line' => $e->getLine(),
                ];
            }

            $isTrivial = $e instanceof Error && ! $e->getPrevious();

            if (! $isTrivial) {
                $debugging               = $e->getPrevious() ?: $e;
                $formattedError['trace'] = static::toSafeTrace($debugging);
            }
        }

        return $formattedError;
    }
Decorates spec-compliant $formattedError with debug entries according to $debug flags
(see GraphQL\Error\Debug for available flags)

@param mixed[]   $formattedError
@param Throwable $e
@param bool|int  $debug

@return mixed[]

@throws Throwable