Skip to content

Print a hint at the end of a run when files were skipped because of errors #8966

Open

Description

@hmennen90

Problem

When a rule throws on a file, Rector reports a system error and skips the whole file. Other files are still changed and the run ends as if it were complete. Nothing at the end says that the result is partial and that a re-run is needed once the cause is fixed.

Example

class Foo
{
    function Foo() {}

    function first($value)
    {
        return $value{0};
    }
}

With a set like LevelSetList::UP_TO_PHP_80, Rector parses the file with its own PHP 7.0 parser, but PHPStan cannot parse $value{0}. The class is unknown to reflection, so Php4ConstructorRector threw Class "Foo" should be known at this point and the file was skipped (fixed for this case in #8965). CurlyToSquareBracketArrayStringRector could have fixed the file, but it never ran on it.

The same happens for any rule that throws on a file: the file is skipped completely and no later rule gets to change it.

Proposal

At the end of a run, if there were system errors and other files were changed in the same run, print a hint, for example:

12 files could not be processed and were skipped. Fix the cause or skip the rule, then run Rector again.

Optionally, when the cause is a parse error PHPStan cannot handle, point to a rule that may fix it.

Questions

  • Is a plain hint after the error list enough, or should it also appear in the JSON/other output formats?
  • Should it change the exit code, or stay informational?

I can open a PR for the plain text hint if this direction is fine.

Activity

  1. TomasVotruba commented on Nov 17, 2026

    @TomasVotruba
    Member

    I just merged #8965, can you try latest rector/rector dev-main to see how it changed the report?

  2. hmennen90 commented on Nov 17, 2026

    @hmennen90
    ContributorAuthor

    Tried latest dev-main on a ~15k file legacy project with LevelSetList::UP_TO_PHP_80: errors went from 7 to 1. The 6 "should be known at this point" errors are gone, those files are processed now.

    One error is left, Node "PhpParser\Node\Expr\Array_" with ... is missing scope from LongArrayToShortArrayRector on a single file. I could not reduce it to a minimal example yet (large file with many gotos).

    The hint at the end of a run about skipped files would still be useful for cases like that one.

  3. TomasVotruba commented on Nov 17, 2026

    @TomasVotruba
    Member

    Great to hear!
    Can you share a miniaml reproducer for the array issue via https://getrector.com/demo ? We'll be able to isolate the fix then.

  4. hmennen90 commented on Nov 17, 2026

    @hmennen90
    ContributorAuthor

    Minimal reproducer for the missing scope error: unreachable code after goto, behind a label that nothing jumps to.

    <?php
    goto end;
    lbl:
    $a = array(1);
    end:

    Config: ->withRules([LongArrayToShortArrayRector::class]) (also happens with LevelSetList::UP_TO_PHP_80), on current dev-main.

    Result: Node "PhpParser\Node\Expr\Array_" with is missing scope required for scope refresh, thrown from ChangedNodeScopeRefresher::refresh(). Without the label it works, with [1] instead of array(1) nothing changes so nothing is refreshed.

    I can open a PR that returns early when there is no scope, if that is the direction you want.

  5. hmennen90 commented on Nov 17, 2026

    @hmennen90
    ContributorAuthor
  6. samsonasik commented on Nov 17, 2026

    @samsonasik
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions