Use new format for logging exceptions - plugins/dns.py (#3191)

Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
Vighnesh Kadam 2021-10-03 22:03:30 +05:30 committed by GitHub
parent ad2566d58a
commit 800fb683f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -178,8 +178,7 @@ class PluginDns(PluginBase):
try:
await self.instance.update(version, image=self.sys_updater.image_dns)
except DockerError as err:
_LOGGER.error("CoreDNS update failed")
raise CoreDNSUpdateError() from err
raise CoreDNSUpdateError("CoreDNS update failed", _LOGGER.error) from err
else:
self.version = version
self.image = self.sys_updater.image_dns
@ -199,8 +198,7 @@ class PluginDns(PluginBase):
try:
await self.instance.restart()
except DockerError as err:
_LOGGER.error("Can't start CoreDNS plugin")
raise CoreDNSError() from err
raise CoreDNSError("Can't start CoreDNS plugin", _LOGGER.error) from err
async def start(self) -> None:
"""Run CoreDNS."""
@ -211,8 +209,7 @@ class PluginDns(PluginBase):
try:
await self.instance.run()
except DockerError as err:
_LOGGER.error("Can't start CoreDNS plugin")
raise CoreDNSError() from err
raise CoreDNSError("Can't start CoreDNS plugin", _LOGGER.error) from err
async def stop(self) -> None:
"""Stop CoreDNS."""
@ -220,8 +217,7 @@ class PluginDns(PluginBase):
try:
await self.instance.stop()
except DockerError as err:
_LOGGER.error("Can't stop CoreDNS plugin")
raise CoreDNSError() from err
raise CoreDNSError("Can't stop CoreDNS plugin", _LOGGER.error) from err
async def reset(self) -> None:
"""Reset DNS and hosts."""
@ -288,8 +284,9 @@ class PluginDns(PluginBase):
},
)
except ConfigurationFileError as err:
_LOGGER.error("Can't update coredns config: %s", err)
raise CoreDNSError() from err
raise CoreDNSError(
f"Can't update coredns config: {err}", _LOGGER.error
) from err
def _init_hosts(self) -> None:
"""Import hosts entry."""
@ -314,8 +311,7 @@ class PluginDns(PluginBase):
try:
self.hosts.write_text(data, encoding="utf-8")
except OSError as err:
_LOGGER.error("Can't update hosts: %s", err)
raise CoreDNSError() from err
raise CoreDNSError(f"Can't update hosts: {err}", _LOGGER.error) from err
def add_host(self, ipv4: IPv4Address, names: list[str], write: bool = True) -> None:
"""Add a new host entry."""