Exception chaining and wrapping improvements (#39320)
* Remove unnecessary exception re-wraps * Preserve exception chains on re-raise We slap "from cause" to almost all possible cases here. In some cases it could conceivably be better to do "from None" if we really want to hide the cause. However those should be in the minority, and "from cause" should be an improvement over the corresponding raise without a "from" in all cases anyway. The only case where we raise from None here is in plex, where the exception for an original invalid SSL cert is not the root cause for failure to validate a newly fetched one. Follow local convention on exception variable names if there is a consistent one, otherwise `err` to match with majority of codebase. * Fix mistaken re-wrap in homematicip_cloud/hap.py Missed the difference between HmipConnectionError and HmipcConnectionError. * Do not hide original error on plex new cert validation error Original is not the cause for the new one, but showing old in the traceback is useful nevertheless.
This commit is contained in:
parent
d768fd4de9
commit
b4bac0f7a0
204 changed files with 550 additions and 518 deletions
|
@ -70,9 +70,9 @@ def _precheck_image(image, opts):
|
|||
raise ValueError()
|
||||
try:
|
||||
img = Image.open(io.BytesIO(image))
|
||||
except OSError:
|
||||
except OSError as err:
|
||||
_LOGGER.warning("Failed to open image")
|
||||
raise ValueError()
|
||||
raise ValueError() from err
|
||||
imgfmt = str(img.format)
|
||||
if imgfmt not in ("PNG", "JPEG"):
|
||||
_LOGGER.warning("Image is of unsupported type: %s", imgfmt)
|
||||
|
@ -272,8 +272,8 @@ class ProxyCamera(Camera):
|
|||
image = await async_get_image(self.hass, self._proxied_camera)
|
||||
if not image:
|
||||
return None
|
||||
except HomeAssistantError:
|
||||
raise asyncio.CancelledError()
|
||||
except HomeAssistantError as err:
|
||||
raise asyncio.CancelledError() from err
|
||||
|
||||
if self._mode == MODE_RESIZE:
|
||||
job = _resize_image
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue