mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-16 21:56:29 +00:00
Capture typeerror exception (#2052)
This commit is contained in:
parent
052a691a4d
commit
c9db42583b
@ -1,15 +1,22 @@
|
|||||||
"""Custom log messages."""
|
"""Custom log messages."""
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import sentry_sdk
|
||||||
|
|
||||||
|
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
RE_BIND_FAILED = re.compile(r".*Bind for.*:(\d*) failed: port is already allocated.*")
|
RE_BIND_FAILED = re.compile(r".*Bind for.*:(\d*) failed: port is already allocated.*")
|
||||||
|
|
||||||
|
|
||||||
def format_message(message: str) -> str:
|
def format_message(message: str) -> str:
|
||||||
"""Return a formated message if it's known."""
|
"""Return a formated message if it's known."""
|
||||||
match = RE_BIND_FAILED.match(message)
|
try:
|
||||||
if match:
|
match = RE_BIND_FAILED.match(message)
|
||||||
return (
|
if match:
|
||||||
f"Port '{match.group(1)}' is already in use by something else on the host."
|
return f"Port '{match.group(1)}' is already in use by something else on the host."
|
||||||
)
|
except TypeError as err:
|
||||||
|
_LOGGER.error("Type of message is not string - %s", err)
|
||||||
|
sentry_sdk.capture_exception(err)
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
@ -9,3 +9,9 @@ def test_format_message():
|
|||||||
format_message(message)
|
format_message(message)
|
||||||
== "Port '80' is already in use by something else on the host."
|
== "Port '80' is already in use by something else on the host."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_exeption():
|
||||||
|
"""Tests the exception handling."""
|
||||||
|
message = b"byte"
|
||||||
|
assert format_message(message) == message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user