Skip to content

Commit 86c4437

Browse files
fix(ui): sanitize authentication error messages in LoadingScreen
1 parent afb4e21 commit 86c4437

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/edit_python_pe/screens/loading.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import TYPE_CHECKING, cast
23

34
from textual import work
@@ -15,6 +16,8 @@
1516
from .dashboard import DashboardScreen
1617
from .quit_confirm import QuitConfirmScreen
1718

19+
logger = logging.getLogger(__name__)
20+
1821

1922
class LoadingScreen(Screen):
2023
def __init__(self, token: str, **kwargs) -> None:
@@ -58,7 +61,7 @@ def check_quit(quit_app: bool | None) -> None:
5861
@work(thread=True, exclusive=True)
5962
def authenticate_and_clone(self) -> None:
6063
try:
61-
_, original_repo = get_repo(self.token)
64+
_token, original_repo = get_repo(self.token)
6265
repo_path, forked_repo = fork_repo(self.token, original_repo)
6366

6467
app = cast("MemberApp", self.app)
@@ -69,8 +72,12 @@ def authenticate_and_clone(self) -> None:
6972
app.token = self.token
7073

7174
self.app.call_from_thread(self.show_success)
72-
except Exception as e:
73-
error_message = str(e)
75+
except Exception:
76+
logger.error("Error during authentication and cloning", exc_info=True)
77+
error_message = _(
78+
"An unexpected error occurred while loading. "
79+
"Please try again or contact support."
80+
)
7481
self.app.call_from_thread(self.show_error, error_message)
7582

7683
def show_success(self) -> None:

tests/unit/screens/test_loading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def test_loading_screen_error(self, mock_get):
4141
if app.screen.query_one("#loading-actions").display:
4242
break
4343
assert app.screen.query_one("#loading-actions").display is True
44-
assert "Auth Error" in str(app.screen.query_one("#result-msg").render())
44+
assert "unexpected error" in str(app.screen.query_one("#result-msg").render())
4545

4646
# Test loading-back
4747
await pilot.click("#loading-back")

0 commit comments

Comments
 (0)