mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
Moved exception handling closer to the cause of error
This commit is contained in:
parent
7e3f86f091
commit
352427e460
1 changed files with 7 additions and 6 deletions
|
@ -46,9 +46,8 @@ class SendMaterialJob(Job):
|
||||||
# Collect materials from the printer's reply and send the missing ones if needed.
|
# Collect materials from the printer's reply and send the missing ones if needed.
|
||||||
try:
|
try:
|
||||||
remote_materials_by_guid = self._parseReply(reply)
|
remote_materials_by_guid = self._parseReply(reply)
|
||||||
|
if remote_materials_by_guid:
|
||||||
self._sendMissingMaterials(remote_materials_by_guid)
|
self._sendMissingMaterials(remote_materials_by_guid)
|
||||||
except json.JSONDecodeError:
|
|
||||||
Logger.logException("w", "Error parsing materials from printer")
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
Logger.logException("w", "Error parsing materials from printer")
|
Logger.logException("w", "Error parsing materials from printer")
|
||||||
|
|
||||||
|
@ -153,12 +152,14 @@ class SendMaterialJob(Job):
|
||||||
# Parses the reply to a "/materials" request to the printer
|
# Parses the reply to a "/materials" request to the printer
|
||||||
#
|
#
|
||||||
# \return a dictionary of ClusterMaterial objects by GUID
|
# \return a dictionary of ClusterMaterial objects by GUID
|
||||||
# \throw json.JSONDecodeError Raised when the reply does not contain a valid json string
|
|
||||||
# \throw KeyError Raised when on of the materials does not include a valid guid
|
# \throw KeyError Raised when on of the materials does not include a valid guid
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
def _parseReply(cls, reply: QNetworkReply) -> Dict[str, ClusterMaterial]:
|
||||||
|
try:
|
||||||
remote_materials = json.loads(reply.readAll().data().decode("utf-8"))
|
remote_materials = json.loads(reply.readAll().data().decode("utf-8"))
|
||||||
return {material["guid"]: ClusterMaterial(**material) for material in remote_materials}
|
return {material["guid"]: ClusterMaterial(**material) for material in remote_materials}
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
Logger.logException("w", "Error parsing materials from printer")
|
||||||
|
|
||||||
## Retrieves a list of local materials
|
## Retrieves a list of local materials
|
||||||
#
|
#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue