From 4262dfaf5dcb1ece926285a3cd076203a3c612a9 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 15 Oct 2021 15:17:59 +0200 Subject: [PATCH] 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. --- cura/PrinterOutput/UploadMaterialsJob.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cura/PrinterOutput/UploadMaterialsJob.py b/cura/PrinterOutput/UploadMaterialsJob.py index 7d2a98ff11..79affeabd3 100644 --- a/cura/PrinterOutput/UploadMaterialsJob.py +++ b/cura/PrinterOutput/UploadMaterialsJob.py @@ -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": {