went through "except Exception:" with a fine comb

This commit is contained in:
Matthias Urlichs committed 2019-02-03 16:39:01 +01:00
1 parent 6310afa261
commit 67c5a5e168
13 files changed
+56 -63

No files matched your search

+2
View File
@@ -18,6 +18,7 @@ import os
import re
import subprocess
import sys
import logging
def get_keywords():
@@ -340,6 +341,7 @@ def git_parse_lookup_file(path):
lookup.append(entry)
except Exception:
# TODO: really catch all exceptions?
logging.getLogger(__name__).exception("Versioneer problem")
break
return lookup
+1 -1
View File
@@ -448,7 +448,7 @@ class CommandTrigger(GenericEventListener):
try:
json_string = json.dumps(payload)
except Exception:
# TODO: log an error?
self._logger.exception("JSON: Cannot dump %r", payload)
json_string = ""
params = {
+2
View File
@@ -1638,6 +1638,7 @@ def is_editable_install(install_dir, package, module, location):
if target == expected_target:
return True
except Exception:
raise # TODO really ignore this?
pass
return False
@@ -1658,6 +1659,7 @@ class EntryPointMetadata(pkginfo.Distribution):
try:
return self.entry_point.dist.get_metadata(metadata_file)
except Exception:
raise # TODO really ignore this?
pass
warnings.warn('No package metadata found for package: {}'.format(self.entry_point.module_name))
@@ -378,7 +378,7 @@ class AnnouncementPlugin(octoprint.plugin.AssetPlugin,
self._logger.info("Loaded channel {} from {} in {:.2}s".format(key, config["url"], time.time() - start))
except Exception as e:
self._logger.exception(
"Could not fetch channel {} from {}: {}".format(key, config["url"], str(e)))
"Could not fetch channel {} from {}".format(key, config["url"]))
return None
response = r.text
+2 -1
View File
@@ -707,7 +707,8 @@ class BackupPlugin(octoprint.plugin.SettingsPlugin,
if callable(on_backup_done):
on_backup_done(name, final_path, exclude)
except Exception:
except Exception as exc:
# TODO py3: use the exception, not sys.exc_info()
if callable(on_backup_error):
exc_info = sys.exc_info()
try:
+2 -2
View File
@@ -463,8 +463,8 @@ class CuraPlugin(octoprint.plugin.SlicerPlugin,
with io.open(path, 'rt', encoding='utf-8') as f:
try:
profile_dict = yaml.safe_load(f)
except Exception:
raise IOError("Couldn't read profile from {path}".format(path=path))
except Exception as exc:
raise IOError("Couldn't read profile from {path}: {exc}".format(path=path), exc=exc)
if "gcode_flavor" in profile_dict and not isinstance(profile_dict["gcode_flavor"], (list, tuple)):
profile_dict["gcode_flavor"] = parse_gcode_flavor(profile_dict["gcode_flavor"])
@@ -858,7 +858,7 @@ class VirtualPrinter(object):
elif select_sd_match is not None:
self._selectSdFile(select_sd_match.group(1))
except Exception:
pass
self._logger.exception("While handling %r", data)
def _listSd(self):
self._send("Begin file list")
@@ -965,10 +965,7 @@ class VirtualPrinter(object):
tool = 0
toolMatch = re.search(r'T([0-9]+)', line)
if toolMatch:
try:
tool = int(toolMatch.group(1))
except Exception:
pass
tool = int(toolMatch.group(1))
if tool >= self.temperatureCount:
return
@@ -1016,7 +1013,7 @@ class VirtualPrinter(object):
if matchF is not None:
try:
self._lastF = float(matchF.group(1))
except Exception:
except ValueError:
pass
speedXYZ = self._lastF * (self._feedrate_multiplier / 100.0)
@@ -1025,6 +1022,9 @@ class VirtualPrinter(object):
if matchX is not None:
try:
x = float(matchX.group(1))
except ValueError:
pass
else:
if self._relative or self._lastX is None:
duration = max(duration, x * self._unitModifier / speedXYZ * 60.0)
else:
@@ -1034,11 +1034,12 @@ class VirtualPrinter(object):
self._lastX += x
else:
self._lastX = x
except Exception:
pass
if matchY is not None:
try:
y = float(matchY.group(1))
except ValueError:
pass
else:
if self._relative or self._lastY is None:
duration = max(duration, y * self._unitModifier / speedXYZ * 60.0)
else:
@@ -1048,11 +1049,12 @@ class VirtualPrinter(object):
self._lastY += y
else:
self._lastY = y
except Exception:
pass
if matchZ is not None:
try:
z = float(matchZ.group(1))
except ValueError:
pass
else:
if self._relative or self._lastZ is None:
duration = max(duration, z * self._unitModifier / speedXYZ * 60.0)
else:
@@ -1062,11 +1064,12 @@ class VirtualPrinter(object):
self._lastZ += z
else:
self._lastZ = z
except Exception:
pass
if matchE is not None:
try:
e = float(matchE.group(1))
except ValueError:
pass
else:
lastE = self._lastE[self.currentExtruder]
if self._relative or lastE is None:
duration = max(duration, e * self._unitModifier / speedE * 60.0)
@@ -1077,8 +1080,6 @@ class VirtualPrinter(object):
self._lastE[self.currentExtruder] += e
else:
self._lastE[self.currentExtruder] = e
except Exception:
pass
if duration:
duration *= 0.1
@@ -1102,22 +1103,22 @@ class VirtualPrinter(object):
if matchX is not None:
try:
self._lastX = float(matchX.group(1))
except Exception:
except ValueError:
pass
if matchY is not None:
try:
self._lastY = float(matchY.group(1))
except Exception:
except ValueError:
pass
if matchZ is not None:
try:
self._lastZ = float(matchZ.group(1))
except Exception:
except ValueError:
pass
if matchE is not None:
try:
self._lastE[self.currentExtruder] = float(matchE.group(1))
except Exception:
except ValueError:
pass
def _writeSdFile(self, filename):
@@ -1135,11 +1136,6 @@ class VirtualPrinter(object):
handle = io.open(file, 'wt', encoding='utf-8')
except Exception:
self._output("error writing to file")
if handle is not None:
try:
handle.close()
except Exception:
pass
self._writingToSdHandle = handle
self._writingToSd = True
self._selectedSdFile = file
@@ -1285,8 +1281,8 @@ class VirtualPrinter(object):
try:
self.outgoing.put(line)
except Exception:
if self.outgoing is None:
pass
if self.outgoing is not None:
raise
def write(self, data):
if self._debug_awol:
+2 -1
View File
@@ -936,7 +936,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
try:
fileData = self._fileManager.get_metadata(FileDestinations.SDCARD if sd else FileDestinations.LOCAL, path_on_disk)
except Exception:
except Exception as exc:
self._logger.exception("Error generating fileData")
fileData = None
if fileData is not None:
if "display" in fileData:
+2
View File
@@ -9,6 +9,7 @@ import io
import os
import tarfile
import zipfile
import logging
try:
from os import scandir
@@ -53,6 +54,7 @@ def getInstalledLanguagePacks():
with io.open(meta_path, 'rt', encoding='utf-8') as f:
meta = yaml.safe_load(f)
except Exception:
logging.getLogger(__name__).exception("Could not load %s", meta_path)
pass
else:
import datetime
-1
View File
@@ -109,7 +109,6 @@ def _get_registered_apps():
additional_apps = hook()
logger.warn("Plugin {} is still implementing the appkey hook that is deprecated since 1.3.11 and will be removed in 1.4.0. Switch it over to the Application Keys Plugin workflow.".format(name))
except Exception:
import logging
logging.getLogger(__name__).exception("Error while retrieving additional appkeys from plugin {name}".format(**locals()))
continue
+14 -22
View File
@@ -250,7 +250,7 @@ class PositionRecord(object):
try:
int(attr[1:])
except Exception:
except ValueError:
return False
return True
@@ -415,7 +415,7 @@ class MachineCom(object):
for key, value in settings().get(["serial", "timeout"], merged=True, asdict=True).items():
try:
self._timeout_intervals[key] = float(value)
except Exception:
except ValueError:
pass
self._consecutive_timeouts = 0
@@ -423,7 +423,7 @@ class MachineCom(object):
for key, value in settings().get(["serial", "maxCommunicationTimeouts"], merged=True, asdict=True).items():
try:
self._consecutive_timeout_maximums[key] = int(value)
except Exception:
except ValueError:
pass
self._max_write_passes = settings().getInt(["serial", "maxWritePasses"])
@@ -2299,6 +2299,7 @@ class MachineCom(object):
except KeyError:
output = template.format(**match.groupdict())
except Exception:
self._logger.debug("Could not proces template %s: %s", template_key, template, exc_info=1)
output = None
if output is not None:
@@ -3527,31 +3528,22 @@ class MachineCom(object):
def _gcode_M155_sending(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs):
match = regexes_parameters["intS"].search(cmd)
if match:
try:
interval = int(match.group("value"))
self._temperature_autoreporting = self._firmware_capabilities.get(self.CAPABILITY_AUTOREPORT_TEMP, False) \
and (interval > 0)
except Exception:
pass
interval = int(match.group("value"))
self._temperature_autoreporting = self._firmware_capabilities.get(self.CAPABILITY_AUTOREPORT_TEMP, False) \
and (interval > 0)
def _gcode_M27_sending(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs):
match = regexes_parameters["intS"].search(cmd)
if match:
try:
interval = int(match.group("value"))
self._sdstatus_autoreporting = self._firmware_capabilities.get(self.CAPABILITY_AUTOREPORT_SD_STATUS, False) \
and (interval > 0)
except Exception:
pass
interval = int(match.group("value"))
self._sdstatus_autoreporting = self._firmware_capabilities.get(self.CAPABILITY_AUTOREPORT_SD_STATUS, False) \
and (interval > 0)
def _gcode_M110_sending(self, cmd, cmd_type=None, gcode=None, subcode=None, *args, **kwargs):
newLineNumber = 0
match = regexes_parameters["intN"].search(cmd)
if match:
try:
newLineNumber = int(match.group("value"))
except Exception:
pass
newLineNumber = int(match.group("value"))
with self._line_mutex:
self._logger.info("M110 detected, setting current line number to {}".format(newLineNumber))
@@ -4232,9 +4224,9 @@ def convert_pause_triggers(configured_triggers):
re.compile(regex)
# add to type list
triggers[t].append(regex)
except Exception:
# invalid regex or something like this, we'll just skip this entry
pass
except Exception as exc:
# invalid regex or something like this
logging.getLogger(__name__).debug("Problem with trigger %r: %s", trigger, str(exc))
result = dict()
for t in triggers.keys():
+5 -5
View File
@@ -249,8 +249,8 @@ class gcode(object):
try:
if self._progress_callback is not None and (lineNo % 1000 == 0) and percentage is not None:
self._progress_callback(percentage)
except Exception:
pass
except Exception as exc:
self._logger.debug("Progress callback %r error: %s", self._progress_callback, exc)
if ';' in line:
comment = line[line.find(';')+1:].strip()
@@ -275,7 +275,7 @@ class gcode(object):
if "filament_diameter" in curaOptions:
try:
self._filamentDiameter = float(curaOptions["filament_diameter"])
except Exception:
except ValueError:
self._filamentDiameter = 0.0
elif comment.startswith("filamentDiameter,"):
# Simplify3D
@@ -483,7 +483,7 @@ def getCodeInt(line, code):
if m < 0:
return int(line[n:])
return int(line[n:m])
except Exception:
except ValueError:
return None
@@ -496,5 +496,5 @@ def getCodeFloat(line, code):
if m < 0:
return float(line[n:])
return float(line[n:m])
except Exception:
except ValueError:
return None
+2 -4
View File
@@ -73,10 +73,8 @@ class LocalStorageTest(unittest.TestCase):
def test_add_file_overwrite(self):
self._add_and_verify_file("bp_case.stl", "bp_case.stl", FILE_BP_CASE_STL)
try:
self._add_and_verify_file("bp_case.stl", "bp_case.stl", FILE_BP_CASE_STL, overwrite=False)
except Exception:
pass
from octoprint.filemanager.storage import StorageError
self.assertRaises(StorageError, self._add_and_verify_file, "bp_case.stl", "bp_case.stl", FILE_BP_CASE_STL, overwrite=False)
self._add_and_verify_file("bp_case.stl", "bp_case.stl", FILE_BP_CASE_STL, overwrite=True)