Improve debug logs in Minecraft Server (#107672)

Improve debug logs
pull/107738/head
elmurato 2024-01-10 14:06:49 +01:00 committed by GitHub
parent 49bdfbd9ca
commit 3fba02a692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -89,7 +89,7 @@ class MinecraftServer:
self._server.timeout = DATA_UPDATE_TIMEOUT
_LOGGER.debug(
"%s server instance created with address '%s'",
"Initialized %s server instance with address '%s'",
self._server_type,
self._address,
)
@ -98,7 +98,15 @@ class MinecraftServer:
"""Check if the server is online, supporting both Java and Bedrock Edition servers."""
try:
await self.async_get_data()
except (MinecraftServerConnectionError, MinecraftServerNotInitializedError):
except (
MinecraftServerConnectionError,
MinecraftServerNotInitializedError,
) as error:
_LOGGER.debug(
"Connection check of %s server failed: %s",
self._server_type,
self._get_error_message(error),
)
return False
return True
@ -108,7 +116,9 @@ class MinecraftServer:
status_response: BedrockStatusResponse | JavaStatusResponse
if self._server is None:
raise MinecraftServerNotInitializedError()
raise MinecraftServerNotInitializedError(
f"Server instance with address '{self._address}' is not initialized"
)
try:
status_response = await self._server.async_status(tries=DATA_UPDATE_RETRIES)

View File

@ -44,17 +44,17 @@ class MinecraftServerConfigFlow(ConfigFlow, domain=DOMAIN):
try:
await api.async_initialize()
except MinecraftServerAddressError:
pass
except MinecraftServerAddressError as error:
_LOGGER.debug(
"Initialization of %s server failed: %s",
server_type,
error,
)
else:
if await api.async_is_online():
config_data[CONF_TYPE] = server_type
return self.async_create_entry(title=address, data=config_data)
_LOGGER.debug(
"Connection check to %s server '%s' failed", server_type, address
)
# Host or port invalid or server not reachable.
errors["base"] = "cannot_connect"