How to handle failures during Document Save

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
heewa
Posts: 5
Joined: Mon May 10, 2021 5:30 pm
Location: New York, USA

How to handle failures during Document Save

Postby heewa » Fri May 14, 2021 5:18 pm

While I was investigating and fixing Issue 4098 (FreeCAD should not exit if unable to rename backup file to project file while exiting), I came across a few failure scenarios in the codepaths for saving a Document which don't error out, but probably should.

The two cases that seemed obvious to me, and for which I have a code change ready to go (see the diff, without a PR here), are:
  1. In BackupPolicy::applyStandard() (App/Document.cpp line 2392) a temporary save file is renamed to the project filename (finalizing the save). If this fails, currently only a warning is logged, but the save is reported as a success.
  2. Similarly, in BackupPolicy::applyStandard() (App/Document.cpp line 2534) the same thing happens, with the same consequences.
Like in Issue 4098, this can cause data loss, so those two cases seem like they should definitely throw an exception, right?

However, I'm less certain about other cases. For example, what should happen when there's a failure to remove a backup file (as part of maintaining some policy), but not in saving the main project file?

Edited to add links to two relevant PRs:
  • PR 4791 Fix lost filename in err msg
  • PR 4792 Fix app quitting despite failing to save project