Catch correct exceptions

To catch the exception of duplicate file types, catch only the exception that triggers at this, OPCError. To catch generic file writing errors, catch all of EnvironmentError, not just OSError.
This commit is contained in:
Ghostkeeper 2021-06-07 14:28:33 +02:00
parent 66f57d4d58
commit 9a65008952
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -5,6 +5,7 @@ from typing import cast, List, Dict
from Charon.VirtualFile import VirtualFile # To open UFP files.
from Charon.OpenMode import OpenMode # To indicate that we want to write to UFP files.
from Charon.filetypes.OpenPackagingConvention import OPCError
from io import StringIO # For converting g-code to bytes.
from PyQt5.QtCore import QBuffer
@ -90,7 +91,7 @@ class UFPWriter(MeshWriter):
try:
archive.addContentType(extension = material_extension, mime_type = material_mime_type)
except:
except OPCError:
Logger.log("w", "The material extension: %s was already added", material_extension)
added_materials = []
@ -130,7 +131,7 @@ class UFPWriter(MeshWriter):
try:
archive.close()
except OSError as e:
except EnvironmentError as e:
error_msg = catalog.i18nc("@info:error", "Can't write to UFP file:") + " " + str(e)
self.setInformation(error_msg)
Logger.error(error_msg)