From 316fa2bd5fee2a5e8ed07ea9d3b3b057f62fc1e5 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Thu, 19 Feb 2026 23:44:39 +0000 Subject: [PATCH] write an error message to the user if a command fails. --- src/q3rcon_tui/tui.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/q3rcon_tui/tui.py b/src/q3rcon_tui/tui.py index ac48e98..3e94b03 100644 --- a/src/q3rcon_tui/tui.py +++ b/src/q3rcon_tui/tui.py @@ -2,7 +2,7 @@ import re from pathlib import Path from typing import Annotated, Type -from aioq3rcon import Client +from aioq3rcon import Client, RCONError from loguru import logger from pydantic import AfterValidator, BeforeValidator from pydantic_settings import BaseSettings, CliSettingsSource, SettingsConfigDict @@ -94,12 +94,19 @@ class RconApp(App): if settings.refresh_output: self.query_one('#response', RichLog).clear() - async with Client(settings.host, settings.port, settings.password) as client: - response = await client.send_command( - self.query_one('#command', Input).value - ) + try: + async with Client( + settings.host, settings.port, settings.password + ) as client: + response = await client.send_command( + self.query_one('#command', Input).value + ) + self.query_one('#response', RichLog).write( + self.remove_color_codes(response.removeprefix('print\n')) + ) + except RCONError as e: self.query_one('#response', RichLog).write( - self.remove_color_codes(response.removeprefix('print\n')) + f'{type(e).__name__}: Unable to connect to server: is the server running and are the host, port, and password correct? ({e})' ) self.query_one('#command', Input).value = ''