From 29d2e5c92112737f371b066a42c02228cb4267ae Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Apr 2020 11:43:25 +0200 Subject: [PATCH] Don't crash if USB device is taken over by other applications or breaks If it happens at just the wrong moment, Cura could crash. Hopefully no longer, though I fear that now it would maybe crash somewhere else with the same error then. We'll find out through new error reports, I hope. Fixes Sentry issue CURA-K8. --- plugins/USBPrinting/USBPrinterOutputDevice.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index adb3b03700..cf07b98ca1 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -191,7 +191,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice): try: self._serial = Serial(str(self._serial_port), self._baud_rate, timeout=self._timeout, writeTimeout=self._timeout) except SerialException: - Logger.log("w", "An exception occurred while trying to create serial connection") + Logger.warning("An exception occurred while trying to create serial connection.") + return + except OSError as e: + Logger.warning("The serial device is suddenly unavailable while trying to create a serial connection: {err}".format(err = str(e))) return CuraApplication.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged) self._onGlobalContainerStackChanged()