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. # Cura is released under the terms of the LGPLv3 or higher.
import configparser import configparser
@ -6,6 +6,7 @@ from io import StringIO
import zipfile import zipfile
from UM.Application import Application from UM.Application import Application
from UM.Logger import Logger
from UM.Preferences import Preferences from UM.Preferences import Preferences
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Workspace.WorkspaceWriter import WorkspaceWriter from UM.Workspace.WorkspaceWriter import WorkspaceWriter
@ -25,6 +26,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
mesh_writer = application.getMeshFileHandler().getWriter("3MFWriter") 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 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 return False
# Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it). # Indicate that the 3mf mesh writer should not close the archive just yet (we still need to add stuff to it).
@ -59,6 +61,7 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
preferences_string = StringIO() preferences_string = StringIO()
temp_preferences.writeToFile(preferences_string) temp_preferences.writeToFile(preferences_string)
preferences_file = zipfile.ZipInfo("Cura/preferences.cfg") preferences_file = zipfile.ZipInfo("Cura/preferences.cfg")
try:
archive.writestr(preferences_file, preferences_string.getvalue()) archive.writestr(preferences_file, preferences_string.getvalue())
# Save Cura version # Save Cura version
@ -77,6 +80,9 @@ class ThreeMFWorkspaceWriter(WorkspaceWriter):
# Close the archive & reset states. # Close the archive & reset states.
archive.close() archive.close()
except PermissionError:
Logger.error("No permission to write workspace to this stream.")
return False
mesh_writer.setStoreArchive(False) mesh_writer.setStoreArchive(False)
return True return True