diff options
author | Ghostkeeper <rubend@tutanota.com> | 2020-07-06 18:42:04 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2020-07-06 18:42:04 +0300 |
commit | c7bbc139f74f12644a3355de8500671879f50fad (patch) | |
tree | 8db23f2439158f92b4ca69dbebe655d2f3343f00 /plugins/3MFWriter | |
parent | 3032221b70118b7f9bfde30c62c2d1eba7e33d00 (diff) |
Catch file writing errors while writing files in the archive
Seems really rare to me, but our users get every possible error some day.
Fixes Sentry issue CURA-ZW.
Diffstat (limited to 'plugins/3MFWriter')
-rw-r--r-- | plugins/3MFWriter/ThreeMFWorkspaceWriter.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py index 4201573c78..2e113e0c4f 100644 --- a/plugins/3MFWriter/ThreeMFWorkspaceWriter.py +++ b/plugins/3MFWriter/ThreeMFWorkspaceWriter.py @@ -127,15 +127,19 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter): file_name = "Cura/%s.%s" % (container.getId(), file_suffix) - if file_name in archive.namelist(): - return # File was already saved, no need to do it again. Uranium guarantees unique ID's, so this should hold. + try: + if file_name in archive.namelist(): + return # File was already saved, no need to do it again. Uranium guarantees unique ID's, so this should hold. - file_in_archive = zipfile.ZipInfo(file_name) - # For some reason we have to set the compress type of each file as well (it doesn't keep the type of the entire archive) - file_in_archive.compress_type = zipfile.ZIP_DEFLATED + file_in_archive = zipfile.ZipInfo(file_name) + # For some reason we have to set the compress type of each file as well (it doesn't keep the type of the entire archive) + file_in_archive.compress_type = zipfile.ZIP_DEFLATED - # Do not include the network authentication keys - ignore_keys = {"network_authentication_id", "network_authentication_key", "octoprint_api_key"} - serialized_data = container.serialize(ignored_metadata_keys = ignore_keys) + # Do not include the network authentication keys + ignore_keys = {"network_authentication_id", "network_authentication_key", "octoprint_api_key"} + serialized_data = container.serialize(ignored_metadata_keys = ignore_keys) - archive.writestr(file_in_archive, serialized_data) + archive.writestr(file_in_archive, serialized_data) + except (FileNotFoundError, EnvironmentError): + Logger.error("File became inaccessible while writing to it: {archive_filename}".format(archive_filename = archive.fp.name)) + return
\ No newline at end of file |