To avoid this I recommend you set up a Github for storing multiple versions and in Construct settings an automatic Google Drive backup every couple minutes, so that if it does happen you can revert to an older file easily and then just add back the code from the new versions. Also if you are using Google Drive to save your file online, right clicking it you have a "Manage Versions" option, there you can download an earlier version of your project that still works...