Catch PermissionError when writing workspaces

We'll want to give a proper error message then. We have no mechanism right now to show a message on the screen particular to this error. Instead we'll let it fail (the user sees a message that writing fails) and put a message in the log why it failed.

Fixes Sentry error CURA-DK.
This commit is contained in:
Ghostkeeper 2020-03-25 09:12:00 +01:00
parent 7ab005e423
commit 2b003c30dc
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2020 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
import configparser
@ -6,6 +6,7 @@ from io import StringIO
import zipfile
from UM.Application import Application
from UM.Logger import Logger
from UM.Preferences import Preferences
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Workspace.WorkspaceWriter import WorkspaceWriter
@ -25,6 +26,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
mesh_writer = application.getMeshFileHandler().getWriter("3MFWriter")
if not mesh_writer: # We need to have the 3mf mesh writer, otherwise we can't save the entire workspace
Logger.error("3MF Writer class is unavailable. Can't write workspace.")
return False
# Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it).
@ -59,24 +61,28 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
preferences_string = StringIO()
temp_preferences.writeToFile(preferences_string)
preferences_file = zipfile.ZipInfo("Cura/preferences.cfg")
archive.writestr(preferences_file, preferences_string.getvalue())
try:
archive.writestr(preferences_file, preferences_string.getvalue())
# Save Cura version
version_file = zipfile.ZipInfo("Cura/version.ini")
version_config_parser = configparser.ConfigParser(interpolation = None)
version_config_parser.add_section("versions")
version_config_parser.set("versions", "cura_version", application.getVersion())
version_config_parser.set("versions", "build_type", application.getBuildType())
version_config_parser.set("versions", "is_debug_mode", str(application.getIsDebugMode()))
# Save Cura version
version_file = zipfile.ZipInfo("Cura/version.ini")
version_config_parser = configparser.ConfigParser(interpolation = None)
version_config_parser.add_section("versions")
version_config_parser.set("versions", "cura_version", application.getVersion())
version_config_parser.set("versions", "build_type", application.getBuildType())
version_config_parser.set("versions", "is_debug_mode", str(application.getIsDebugMode()))
version_file_string = StringIO()
version_config_parser.write(version_file_string)
archive.writestr(version_file, version_file_string.getvalue())
version_file_string = StringIO()
version_config_parser.write(version_file_string)
archive.writestr(version_file, version_file_string.getvalue())
self._writePluginMetadataToArchive(archive)
self._writePluginMetadataToArchive(archive)
# Close the archive & reset states.
archive.close()
# Close the archive & reset states.
archive.close()
except PermissionError:
Logger.error("No permission to write workspace to this stream.")
return False
mesh_writer.setStoreArchive(False)
return True