mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-14 12:46:32 +00:00
Capture typeerror exception (#2052)
This commit is contained in:
parent
052a691a4d
commit
c9db42583b
@ -1,15 +1,22 @@
|
||||
"""Custom log messages."""
|
||||
import logging
|
||||
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.*")
|
||||
|
||||
|
||||
def format_message(message: str) -> str:
|
||||
"""Return a formated message if it's known."""
|
||||
match = RE_BIND_FAILED.match(message)
|
||||
if match:
|
||||
return (
|
||||
f"Port '{match.group(1)}' is already in use by something else on the host."
|
||||
)
|
||||
try:
|
||||
match = RE_BIND_FAILED.match(message)
|
||||
if match:
|
||||
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
|
||||
|
@ -9,3 +9,9 @@ def test_format_message():
|
||||
format_message(message)
|
||||
== "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