Catch environment errors when restoring back-ups

There could be an environment error when saving that file because of access rights or insufficient disk space. Catch that error and display an error message to the user. The log then contains more information on exactly why it failed, but the user just knows it fails.

Fixes Sentry issue CURA-21W.
This commit is contained in:
Ghostkeeper 2021-04-16 14:14:21 +02:00
parent acb0c57026
commit 0d29610899
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -1,3 +1,6 @@
# Copyright (c) 2021 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import base64 import base64
import hashlib import hashlib
import threading import threading
@ -56,14 +59,20 @@ class RestoreBackupJob(Job):
return return
# We store the file in a temporary path fist to ensure integrity. # We store the file in a temporary path fist to ensure integrity.
temporary_backup_file = NamedTemporaryFile(delete = False) try:
with open(temporary_backup_file.name, "wb") as write_backup: temporary_backup_file = NamedTemporaryFile(delete = False)
app = CuraApplication.getInstance() with open(temporary_backup_file.name, "wb") as write_backup:
bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE) app = CuraApplication.getInstance()
while bytes_read:
write_backup.write(bytes_read)
bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE) bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
app.processEvents() while bytes_read:
write_backup.write(bytes_read)
bytes_read = reply.read(self.DISK_WRITE_BUFFER_SIZE)
app.processEvents()
except EnvironmentError as e:
Logger.log("e", f"Unable to save backed up files due to computer limitations: {str(e)}")
self.restore_backup_error_message = self.DEFAULT_ERROR_MESSAGE
self._job_done.set()
return
if not self._verifyMd5Hash(temporary_backup_file.name, self._backup.get("md5_hash", "")): if not self._verifyMd5Hash(temporary_backup_file.name, self._backup.get("md5_hash", "")):
# Don't restore the backup if the MD5 hashes do not match. # Don't restore the backup if the MD5 hashes do not match.