Handle both cases of bind failures (#2099)

This commit is contained in:
Joakim Sørensen 2020-10-06 11:28:09 +02:00 committed by GitHub
parent 38db375fea
commit 9dc2f43ffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -6,7 +6,9 @@ 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".*[listen tcp|Bind for].*(?:[0-9]{1,3}\.){3}[0-9]{1,3}:(\d*).*[bind|failed]:[address already in use|port is already allocated].*"
)
def format_message(message: str) -> str:

View File

@ -2,7 +2,7 @@
from supervisor.utils.log_format import format_message
def test_format_message():
def test_format_message_port():
"""Tests for message formater."""
message = '500 Server Error: Internal Server Error: Bind for 0.0.0.0:80 failed: port is already allocated")'
assert (
@ -11,6 +11,15 @@ def test_format_message():
)
def test_format_message_port_alternative():
"""Tests for message formater."""
message = 'Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use")'
assert (
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"