-
-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rector deletes contents of file when it encounters an error #6646
Comments
Hi, thanks for repoting. It's hard to guess where exactly is the problem and what we need to fix. |
I fall into same issue when I forgot |
That cannot happen. Could you share an repository with this bug? |
It's difficult since this was for work and I don't want to share such code publicly. I'll see if I can create an example that occurs reliably though. |
Thank you 👍 |
My case you can reproduce pretty simple:
Content disappears:
And then the same with
It works!
|
Probably this error cause it:
But if there is such error, Rector should not delete content, just throw error. What was your error @devbanana? |
Yes, my error looked very similar to yours @lulco . When Rector throws an error like that it deletes the content of the file. |
I created PR rectorphp/rector-src#716 , please try that and verify if that fixes the issue. |
Works for me, thx Maybe @frankdejonge has same issue? https://twitter.com/frankdejonge/status/1419577807823384576 |
rectorphp/rector-src@8ed98c1 [DX] Use Param->isPromoted() over param->flags !== 0 check on promotion property check (#6646)
Bug Report
This one is hard to debug because it seems intermittent, but I'll describe how I got there.
Basically I was using
RenameClassRector
to move some classes from one namespace to another. I couldn't useRenameNamespaceRector
because only a few classes were moving to the new location. Anyway the important thing is that the class kept the same name, just in a new namespace.Anyway for a few files which used these moved classes (not for all of them for some reason, just a few), it got into a state where the use statement was added for the new namespace, but the old was not removed.
If I then ran Rector again, it threw an error and deleted the whole contents of the file.
So for example if I had a class
Foo\Old\Bar
and wanted to move it toFoo\New\Bar
, some other file, like a unit test, might include this:Then when Rector was run on this, it would encounter an error and delete the whole contents of the file (only a blank file was left).
I ran this on a whole directory and didn't catch that it had deleted some of my files until several commits later.
The main thing to be fixed here I think is that a file's contents shouldn't be deleted when an error is encountered.
I'm sorry I can't provide more useful information.
The text was updated successfully, but these errors were encountered: