I've been working on an Arduino project for the last week or so. I started with a .ino file and was taking a look at this article from PlatformIO on how to convert my .ino file to .cpp.
After changing the extension of my primary project file from .ino to .cpp, Arduino IDE threw out a few errors and dialogues all my files were removed from the project.
I tried going to the directory and it is gone without a trace. There is nothing in my trash bin. Nothing in Recent projects.
It seems that Arduino IDE's attempt to force the folder name to be the same as the main project file name has resulted in the IDE crashing after deleting the file, but before restoring the file. The files are nowhere to be found on my system, so I can only assume that it was either saved in a tmp file or it was being held in local memory.
Fortunately, I just committed my changes last night, so I won't be losing any progress, but this could have been a nightmare.
That was quite a long time ago in terms of the Arduino IDE development. It was in an early beta development phase at that time and Arduino was distributing it in order to allow the community to contribute to the development of the project through beta testing. It was not intended to be used as a primary tool for sketch development at that time. Since then, the IDE has become far more reliable thanks to the valuable feedback from the community and the work of Arduino's developers.
So I am not convinced the problem you experienced is the same, but it might be. There is one known bug in the current version of Arduino IDE that can cause the loss of the unsaved sketch contents:
but your description does not match well against the conditions that bug occurs under, so I'm not convinced it is the same.
Are you able to reproduce the bug? If so, please provide detailed instructions I can follow to reproduce it. That information will be very valuable in the investigation and resolution of the bug.
Arduino IDE puts a slightly modified copy of your sketch program in the system temporary folder every time you compile. Assuming you were compiling the sketch periodically while working on it, you may be able to recover a recent version of the sketch from this temporary build folder.
Which operating system are you using (e.g., "Windows")?
I ask because I can give you more information on the location of the temporary build folders, which are in an operating system-specific location.
Hey @ptillisch, thanks for getting back to me! and no worries, I'm just glad I backed everything up on GitHub last night as even the .git file has disappeared
I was able to reproduce the bug. Here's a bug report:
OS: MacOS Ventura 13.1
Arduino IDE version: 2.0.3
Expected: When working within a project directory in Arduino IDE and viewing the Explorer tab and right clicking the main .ino file to "Rename", I want to provide a new file extension that will be saved to the selected directory, so I don't have to stick with .ino files.
Actual: When right clicking the main .ino file in the Explorer tab and pressing "Rename", I am prompted with the file explorer that allows me to choose a new name for my project, but saving that file to the same directory as my existing project resulted in the entire directory being removed.
Steps to reproduce:
Create a new Sketch and save it to your projects folder. For this report, we will simply call the created file main.ino.
Open the explorer tab, right click the main.ino file, and select "Rename".
A file explorer modal will pop-up and navigate to the Arduino root folder.
Navigate to the project folder, change the file name input to main.cpp, and press Save.
Arduino IDE will flicker, the open project files will close, and error messages will appear saying "Unable to watch for file changes in this large workspace. Please follow the instructions link to resolve this issue."
All files will be missing from the Explorer tab. Navigating to the folder in Finder shows that the folder is completely gone and was not sent to the trash bin.
I am okay with recovery, I think, but I appreciate your offer to help! I mostly want to make sure this bug report is submitted so no one else runs into this issue again in the future.
Hi again! I'm sorry for making three comments in a row on the same post, but I wanted to add some information regarding how I recovered my files.
After creating a new Sketch, I went to menu bar and clicked Sketch -> Show Sketch Folder. This opened a finder window. Navigating above that folder showed a bunch of "unsaved" Arduino folders. After clicking through a few of the folders, I found my old files safely tucked away.
Thanks for the help and let me know if there's anything else I can do to help with the bug report.
I am able to reproduce the fault with the latest nightly build by following your instructions. More importantly, I am able to reproduce the fault using the IDE's primary UI (the IDE's Explorer view is an unsupported "use at your own risk" feature so the project managers are unlikely to allocate resources to fixing bugs specific to Explorer), and also found the unsupported use of a .cpp extension for the rename target is not a required condition.
I submitted a formal report to the developers on your behalf: