diff --git a/pyproject.toml b/pyproject.toml index 6282b4d..09c0ba6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -105,7 +105,6 @@ ignore = [ "B008", # Do not perform function call "S110", # `try`-`except`-`pass` detected, consider logging the exception "D106", # Missing docstring in public nested class - "B904", "UP007", # typer needs Optional syntax "UP038", # Use `X | Y` in `isinstance` is slower "S603", # check for execution of untrusted input diff --git a/src/uvcclient/camera.py b/src/uvcclient/camera.py index 5c9b752..db60255 100644 --- a/src/uvcclient/camera.py +++ b/src/uvcclient/camera.py @@ -51,10 +51,10 @@ def _safe_request(self, *args, **kwargs): conn = httplib.HTTPConnection(self._host, self._port) conn.request(*args, **kwargs) return conn.getresponse() - except OSError: - raise CameraConnectError("Unable to contact camera") + except OSError as ex: + raise CameraConnectError("Unable to contact camera") from ex except httplib.HTTPException as ex: - raise CameraConnectError(f"Error connecting to camera: {ex!s}") + raise CameraConnectError(f"Error connecting to camera: {ex!s}") from ex def login(self): resp = self._safe_request("GET", "/") diff --git a/src/uvcclient/nvr.py b/src/uvcclient/nvr.py index 1491986..1551778 100755 --- a/src/uvcclient/nvr.py +++ b/src/uvcclient/nvr.py @@ -96,18 +96,18 @@ def _safe_request(self, *args, **kwargs): conn = self._get_http_connection() conn.request(*args, **kwargs) return conn.getresponse() - except OSError: - raise CameraConnectionError("Unable to contact camera") + except OSError as ex: + raise CameraConnectionError("Unable to contact camera") from ex except httplib.HTTPException as ex: - raise CameraConnectionError(f"Error connecting to camera: {ex!s}") + raise CameraConnectionError(f"Error connecting to camera: {ex!s}") from ex def _uvc_request(self, *args, **kwargs): try: return self._uvc_request_safe(*args, **kwargs) - except OSError: - raise NvrError("Failed to contact NVR") + except OSError as ex: + raise NvrError("Failed to contact NVR") from ex except httplib.HTTPException as ex: - raise NvrError(f"Error connecting to camera: {ex!s}") + raise NvrError(f"Error connecting to camera: {ex!s}") from ex def _uvc_request_safe( self, path, method="GET", data=None, mimetype="application/json" @@ -204,10 +204,10 @@ def set_picture_settings(self, uuid, settings): dtype = type(data["data"][0]["ispSettings"][key]) try: data["data"][0]["ispSettings"][key] = dtype(settings[key]) - except ValueError: + except ValueError as ex: raise Invalid( f"Setting `{key}' requires {dtype.__name__} not {type(settings[key]).__name__}" - ) + ) from ex data = self._uvc_request(url, "PUT", json.dumps(data["data"][0])) return data["data"][0]["ispSettings"] diff --git a/src/uvcclient/store.py b/src/uvcclient/store.py index 7e23ca4..5d87784 100644 --- a/src/uvcclient/store.py +++ b/src/uvcclient/store.py @@ -27,7 +27,7 @@ def load(self): self._data = {} except Exception as ex: LOG.error("Failed to read store data: %s", ex) - raise UnableToManageStore("Unable to write to store") + raise UnableToManageStore("Unable to write to store") from ex def save(self): try: @@ -36,7 +36,7 @@ def save(self): os.chmod(self._path, 0o600) except OSError as ex: LOG.error("Unable to write store: %s", str(ex)) - raise UnableToManageStore("Unable to write to store") + raise UnableToManageStore("Unable to write to store") from ex def get_camera_passwords(self): return self._data.get("camera_passwords", {})