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