How the heck does IDE 2.0.3 save stuff?

I've just lost an entire day's editing because I don't understand why, no matter how many times I hit Save during a lengthy editing session, the IDE then prompts me to save or save a copy when I exit. Clearly save doesn't mean save, so I chose Save a copy.

Then, outside of IDE, I renamed the 'copy' which had the timedate stamp added to the file name, to what I called it before the day's editing. Now when I open IDE I just get the old version - without any inkling of a hard day's brain work put into the editing.

To say I'm not happy is a gross understatement.

I've never struck any other application where Save doesn't mean save the file you have open.

The editor has some improved features but I've learned the hard way never to trust it again.

I'm not the one that can give you all details or a solution.

"Save" (and "Save As") save a complete copy of your sketch. If your sketch has multiple tabs, the IDE saves all of them.

Where is the sketch that you were working on located? What is your sketchbook location? Where do you "Save As" your sketch to?

That should not happen. The only time that I have been prompted when I exit the IDE is if I have turned autosave off; I can not remember if I modified and saved the project before I did the exit.

The autosave option is quite hidden, please check

  1. In the IDE, press <ctrl><shift><P>
  2. Type autosave an check if there is a tick in front of it.
  3. If not, you can click it to enable it.

There seems to be a step missing. If you have a projectA directory and a projectA_copy_yyyymmdd (something like that) directyory in the same parent directory, you can not rename the second one to the first one without deleting the first one first.

Be aware that the there are two things that you need to rename; the directory itself as well as the Ino file.

Which operating system are you using?

I've moved your topic to the dedicated IDE 2.0 section of the forum.

Thanks for your swift reply! Answering the simple ones first:

Windows 10

I didn't know it had that feature. Very reluctantly I've opened 2.0.3 again to check and it's ticked.

I didn't think I needed to mention that but, yes, because I wanted to retain the name I had to delete the old folder first. And since I did this in Windows Explorer, I really am confused as to how I ended up with the sketch that I thought I'd deleted. And yes, the .ino file was also renamed - otherwise IDE would not have opened it because of the mismatch in names.
I thought this would be OK but how the hell I ended up with the old sketch without the days edits ... is a mystery to me and pretty scary.
Rhetorical question: Would the edits be there in the copy if I hadn't chosen to change its name?
I've looked in my Recycle bin and, while there is a folder there with the old name, when I go to restore it, Windows gives me dire warnings that things may not work properly if I do that. I tried(!) but found it was full of various empty files - some of which are a mystery to me (.theia?). There's obviously a lot more happening under the hood wrt saving in IDE.

I save most sketch folders in the folder Sketchbook, which hangs off an Arduino folder in my Documents. So at C:\Users\John\Documents\Arduino\Sketchbook. However, this particular project I keep in a folder that's on the same level as Sketchbook, under Arduino. Certainly in the older v1.8.something IDE, you seemed to be free to create and use folders as you wanted (provided you had access, of course). If we're going to be restricted to the folder specifically called Sketchbook, for example, I think that should be made very clear.
Anyway, I have a day's re-work (in the old IDE) to look forward to tomorrow :frowning:

Problem is that I / we don't know who we are dealing with; experienced programmer / windows user or somebody new to all of it. I've learned to expect the unexpected where someone (in this scenario) ignored the Windows warning / error and expected it to work. No offense intended, I was just making sure.

OK, reason for asking was if it was maybe on something like Google Drive, Microsoft's OneDrive or even a local network drive. People often seem to battle with that.

To my knowledge you're free to choose any directory. Mine are all over the show (though most of them are in the sketchbook directory).

My system with IDE 2.0.3 is currently down due to load shedding :frowning: So no chance of testing and checking.

There is a temporary directory where the IDE actually copies the files to before the actual compiling happens. As it is temporary you might be out of luck as it should be cleaned out when you close the IDE but you can search the AppData folder for *.ino.cpp and try to find the sketch back.

Hi @johnrippon. I'm sorry to hear about the problem with Arduino IDE.

First of all, you should be aware that 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 should be able to recover a recent version of the sketch from this temporary build folder.

It will be in a folder at the path with this form:

C:\Users\per\AppData\Local\Temp\arduino-sketch-<some hash>\sketch\<sketch name>.ino.cpp

:exclamation: If looking for it with your file browser or command line, note that the AppData folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".

The <some hash> placeholder in the path above will be some hash value (e.g., 509E44CE886254F3BD168D77BFBA2ECA), so you will need to search through the various folders to find your sketch.

The <sketch name> placeholder in the path above will be the sketch name.

The .ino.cpp file is the product of the Arduino sketch preprocessor converting the .ino files of the sketch into valid C++ via this procedure:

  1. If there are multiple .ino files in the sketch, concatenate them into a single file, starting with the file that matches the sketch folder name, followed by the rest in alphabetical order.
  2. Add #include <Arduino.h> at the top of the file, if an #include directive for that file doesn't already exist.
    Arduino.h contains declarations of the standard Arduino core library API, which is documented in the Arduino Language Reference.
  3. Insert automatically generated function prototypes for any function that doesn't already have one.
  4. Add #line directives to make warning/error messages still match the original sketch files.

So the .ino.cpp file will be slightly different than the Arduino code in your sketch, but converting it back to Arduino language will only take a couple minutes of work. We can help you out with that if needed.

If your sketch contains .h, .cpp, .c, .S files, those will be in the folder along with the .ino.cpp file. Those files will be unmodified.


Now to talk about the problem. Several users have reported a problem like this. They found the read-only file attribute was set on the sketch. A user investigated this and determined Windows was the one setting the attribute (as opposed to Arduino IDE setting it):

This mysterious attribute set becomes especially dangerous when combined with the known bug in Arduino IDE which causes it to fail a save silently when the sketch has the read-only file attribute:

Thanks so much @ptillisch! I do appreciate the effort you've put into this detailed explanation.

So if I've understood you correctly I was naive in assuming, if I hit Save and don't get any warning that the sketch couldn't be saved (for whatever reason), that it had indeed been saved (hidden copies aside)! To me, that's the bottom line and in future I'll regularly copy and paste the entire sketch into a separate file and save it independently of the Arduino IDE. It seems crazy that the user gets no inkling of the system's failure not to save. Windows usually does warn in my experience. But given the work that goes into creating complex sketches, that's what I'm going to do just to take advantage of the positive features of the IDE editor. We learn the hard way!

Unfortunately I don't think I compiled the sketch very often, if at all. Most of the time was put into creating rather complex logic. Also, I don't yet have all the hardware mocked up to upload and run the program.

I'm still not sure why even the copy with the datetime stamp in the title didn't reflect any of the editing I'd done but I really need to cut my loses rather than waste more time on analysing the problem. At least I've learned that I'm not alone in experiencing this problem.

Just one question: Do you know whether this idiosyncrasy also applies to IDE 1.8.15? I've been using Arduino IDEs (1.x versions) for about four years now and never before experience this.

You installed the IDE in a place you do not have privileges or you tried to save over a built-in example.

I wouldn't say "naïve". This is a completely reasonable expectation.

I'll repeat again: if Arduino IDE is not communicating a failure to save a sketch, that is a bug. This is not the intended behavior of Arduino IDE.

The known bug I mentioned in my previous reply is caused by saving to an existing sketch that has the read-only file attribute set. That wouldn't apply to saving a new sketch. So I don't have any explanation for this.

xfpd's hypothesis that the location you saved the sketch to has some restrictions that make it "read-only" to the IDE is reasonable. But you mentioned that you save sketches under C:\Users\John\Documents\Arduino\Sketchbook, which I would expect to be accessible.

Please note the other users were attempting to save to a existing sketch that has the read-only file attribute set. We don't have any reports of the latest version of Arduino IDE failing to save under any other conditions.

I would be very interested in knowing about other conditions under which the IDE fails to save the sketch without communicating the problem to the user. Unfortunately I can't reproduce the problem on my computer and it sounds like you are not interested in spending more time on investigating the problem:

I am not aware of any problems with saving in Arduino IDE 1.x. Arduino IDE 2.x is a complete rewrite of Arduino IDE in a different programming language, sharing zero code with Arduino IDE 1.x, so it is not expected that an application-specific bug in one IDE will occur in the other.

1 Like

@ptillisch Thanks again.

Thanks but not sure I follow you. It was a standard installation. How could I have installed it to a location to which I didn't have access? It's worked fine until this one time.

As already pointed out, the sketch was saved in a folder of my own choice and under my stock standard Windows user documents folder, nowhere near any 'examples'. Sketch was called "controller_v100a", so very much doubt any examples even have that name.

I do not know, but I managed to do something wrong long ago (I probably installed in root, but only signed in with user privs). My experience was that I could never save, rather I could only save a copy to. Another thing I did wrong was to move a folder. The IDE did not like that and protested everything I did. Uninstalled-reinstalled to correct them.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.