From ee625eb953977a81c7c332f5be61e8816e901cf6 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Wed, 20 Aug 2025 04:10:07 +0000 Subject: [PATCH] Fix CLI abort status bug by replacing typer.Abort() with typer.Exit(1) This ensures consistent exit codes when the CLI encounters errors. Co-authored-by: Rushil Patel --- src/codegen/cli/auth/decorators.py | 2 +- src/codegen/cli/auth/session.py | 6 +++--- src/codegen/cli/errors.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/codegen/cli/auth/decorators.py b/src/codegen/cli/auth/decorators.py index df4c5781f..a430f0ac3 100644 --- a/src/codegen/cli/auth/decorators.py +++ b/src/codegen/cli/auth/decorators.py @@ -22,7 +22,7 @@ def wrapper(*args, **kwargs): # Check for valid session if session is None: pretty_print_error("There is currently no active session.\nPlease run 'codegen init' to initialize the project.") - raise typer.Abort() + raise typer.Exit(1) if (token := get_current_token()) is None: rich.print("[yellow]Not authenticated. Let's get you logged in first![/yellow]\n") diff --git a/src/codegen/cli/auth/session.py b/src/codegen/cli/auth/session.py index 65c0407d8..e442eb896 100644 --- a/src/codegen/cli/auth/session.py +++ b/src/codegen/cli/auth/session.py @@ -24,14 +24,14 @@ class CodegenSession: def __init__(self, repo_path: Path, git_token: str | None = None) -> None: if not repo_path.exists(): rich.print(f"\n[bold red]Error:[/bold red] Path to git repo does not exist at {repo_path}") - raise typer.Abort() + raise typer.Exit(1) # Check if it's a valid git repository try: LocalGitRepo(repo_path=repo_path) except Exception: rich.print(f"\n[bold red]Error:[/bold red] Path {repo_path} is not a valid git repository") - raise typer.Abort() + raise typer.Exit(1) self.repo_path = repo_path self.local_git = LocalGitRepo(repo_path=repo_path) @@ -87,7 +87,7 @@ def _validate(self) -> None: except BadCredentialsException: rich.print(format_command(f"\n[bold red]Error:[/bold red] Invalid GitHub token={git_token} for repo={self.local_git.full_name}")) rich.print("[white]Please provide a valid GitHub token for this repository.[/white]") - raise typer.Abort() + raise typer.Exit(1) def __str__(self) -> str: return f"CodegenSession(user={self.config.repository.user_name}, repo={self.config.repository.name})" diff --git a/src/codegen/cli/errors.py b/src/codegen/cli/errors.py index a4f0fd536..4de28cfc1 100644 --- a/src/codegen/cli/errors.py +++ b/src/codegen/cli/errors.py @@ -55,6 +55,6 @@ def wrapper(*args, **kwargs): return f(*args, **kwargs) except AuthError: rich.print(Panel("[red]Authentication Error:[/red] Please run 'codegen login' first.", title="Codegen Error", border_style="red")) - raise typer.Abort() + raise typer.Exit(1) return wrapper