Better handle errors in local part of upload job

It could be that the archive fails to save because the user doesn't have access to its own temporary folder, the firewall quarantines the archive, there's not enough disk space, whatever. These errors need to be handled and not crash Cura.

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-15 15:17:59 +02:00
parent dfcefe11cc
commit 4262dfaf5d
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -75,12 +75,22 @@ class UploadMaterialsJob(Job):
for printer in self._printer_metadata:
self._printer_sync_status[printer["host_guid"]] = self.PrinterStatus.UPLOADING.value
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
archive_file.close()
self._archive_filename = archive_file.name
try:
archive_file = tempfile.NamedTemporaryFile("wb", delete = False)
archive_file.close()
self._archive_filename = archive_file.name
self._material_sync.exportAll(QUrl.fromLocalFile(self._archive_filename), notify_progress = self.processProgressChanged)
except OSError as e:
Logger.error(f"Failed to create archive of materials to sync with printers: {type(e)} - {e}")
self.failed(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to create archive of materials to sync with printers.")))
return
self._material_sync.exportAll(QUrl.fromLocalFile(self._archive_filename), notify_progress = self.processProgressChanged)
file_size = os.path.getsize(self._archive_filename)
try:
file_size = os.path.getsize(self._archive_filename)
except OSError as e:
Logger.error(f"Failed to load the archive of materials to sync it with printers: {type(e)} - {e}")
self.failed(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to load the archive of materials to sync it with printers.")))
return
request_metadata = {
"data": {