Skip to content

Incorrect behavior of ThrowWithPreviousExceptionRector #9671

@eexit

Description

@eexit

Bug Report

Subject Details
Rector version last dev-main/2.3.8
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/f5724dc1-f9d3-4950-ba1d-d7fee6331452

<?php declare(strict_types=1);

namespace GraphQL\Error;

use GraphQL\Language\AST\Node;
use GraphQL\Language\Source;

class Error extends \Exception
{
    /**
     * @param iterable<array-key, Node|null>|Node|null $nodes
     * @param array<int, int>|null $positions
     * @param list<int|string>|null $path
     * @param array<string, mixed>|null $extensions
     * @param list<int|string>|null $unaliasedPath
     */
    public function __construct(
        string $message = '',
        $nodes = null,
        ?Source $source = null,
        ?array $positions = null,
        ?array $path = null,
        ?\Throwable $previous = null,
        ?array $extensions = null,
        ?array $unaliasedPath = null
    ) {
        parent::__construct($message, 0, $previous);
    }
}

try {
    throw new \InvalidArgumentException('foo');
} catch (\InvalidArgumentException $e) {
    throw new Error(message: 'Some error message', previous: $e);
}

Responsible rules

  • ThrowWithPreviousExceptionRector

Expected Behavior

No change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions