Skip to content

Fix syntax error from orphaned else block in cli.py#90

Merged
AdmGenSameer merged 3 commits into
mainfrom
copilot/fix-syntax-error-in-cli
Dec 9, 2025
Merged

Fix syntax error from orphaned else block in cli.py#90
AdmGenSameer merged 3 commits into
mainfrom
copilot/fix-syntax-error-in-cli

Conversation

Copilot AI commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

Description

Syntax error at line 1047 prevented archpkg from running. The outer try block at line 976 was missing its exception handler, and an orphaned else: block referenced undefined variables (packages, source, track) that don't exist in the handle_search_command function context.

Related Issue

Fixes #(issue number if available)

Changes Made

  • Removed orphaned else: block (lines 1047-1067) containing misplaced batch installation logic
  • Added missing except KeyboardInterrupt handler for outer try block
  • Fixed package_namepkg variable references (2 locations)
  • Removed dead tracking code referencing undefined track variable

Before:

try:
    # ... interactive installation flow
    try:
        # ... inner try block
    except KeyboardInterrupt:
        # ... handles inner try only
else:  # ← Orphaned else with undefined variables
    logger.info(f"Installing multiple packages: {packages}")
    if track:  # ← undefined
        # ...

After:

try:
    # ... interactive installation flow
    try:
        # ... inner try block
    except KeyboardInterrupt:
        # ... handles inner try only
except KeyboardInterrupt:  # ← Added handler for outer try
    console.print("\n[yellow]Installation cancelled.[/yellow]")
    raise typer.Exit(1)

Screenshots or GIFs (if applicable)

N/A - Syntax fix only

Checklist

  • Code is formatted with the project's Prettier config provided in .prettierrc (if present).
  • Only the necessary files are modified; no unrelated changes are included.
  • Follows clean code principles (readable, maintainable, minimal duplication).
  • All changes are clearly documented.
  • Code has been tested (manual/automated) and verified against edge cases.
  • No breaking changes are introduced to existing functionality.
  • All new and existing tests passed (if tests exist).

Additional Notes

Changes are minimal and surgical: 28 lines removed, 3 lines added. Python syntax check, code review, and CodeQL security scan all pass.

Original prompt

Problem

After merging PR #66, archpkg fails to run with a syntax error:

Traceback (most recent call last):
  File "/home/samarcher/.local/bin/archpkg", line 3, in <module>
    from archpkg.cli import main
  File "/home/samarcher/.local/share/pipx/venvs/archpkg/lib/python3.13/site-packages/archpkg/cli.py", line 1047
    else:
    ^^^^
SyntaxError: expected 'except' or 'finally' block

Root Cause

There's a syntax error in archpkg/cli.py around line 1047. The code structure is broken:

  1. There's a try block starting at line 976
  2. An except KeyboardInterrupt block at line 1044-1046
  3. Then an orphaned else: at line 1047 that Python expects to be part of the try-except structure

The else: block (lines 1047-1067) appears to be meant for batch installation of multiple packages, but it's incorrectly placed after the except block. This looks like it should be part of an if-else statement checking whether we're installing a single package or multiple packages.

Fix Required

The code in archpkg/cli.py from approximately line 976 to 1067 needs to be restructured. Looking at the code:

  1. The try block at line 976 handles single package installation interactively
  2. The else: block at line 1047 is for batch installation when multiple packages are specified
  3. But there's no corresponding if statement - the code flow is broken

The fix should:

  1. Remove or properly integrate the orphaned else: block (lines 1047-1067)
  2. The batch installation logic (calling batch_install_packages) should either be:
    • Removed if it's not needed in the search command context
    • Or properly integrated with an if condition checking for multiple packages

Looking at the context, the search command at line 585 only handles a single query string, so the batch installation else block seems to be misplaced code that shouldn't be in the search command's handle_search_command function. This block likely belongs to an install command that wasn't fully merged.

The simplest fix is to remove lines 1047-1067 (the orphaned else: block) since:

  • The search command only searches for one query at a time
  • Batch installation logic is already in batch_install_packages() function
  • There are references to undefined variables like packages, source, and track in that block

Files to Modify

  • archpkg/cli.py - Fix the syntax error by removing the orphaned else block (lines 1047-1067)

This pull request was created as a result of the following prompt from Copilot chat.

Problem

After merging PR #66, archpkg fails to run with a syntax error:

Traceback (most recent call last):
  File "/home/samarcher/.local/bin/archpkg", line 3, in <module>
    from archpkg.cli import main
  File "/home/samarcher/.local/share/pipx/venvs/archpkg/lib/python3.13/site-packages/archpkg/cli.py", line 1047
    else:
    ^^^^
SyntaxError: expected 'except' or 'finally' block

Root Cause

There's a syntax error in archpkg/cli.py around line 1047. The code structure is broken:

  1. There's a try block starting at line 976
  2. An except KeyboardInterrupt block at line 1044-1046
  3. Then an orphaned else: at line 1047 that Python expects to be part of the try-except structure

The else: block (lines 1047-1067) appears to be meant for batch installation of multiple packages, but it's incorrectly placed after the except block. This looks like it should be part of an if-else statement checking whether we're installing a single package or multiple packages.

Fix Required

The code in archpkg/cli.py from approximately line 976 to 1067 needs to be restructured. Looking at the code:

  1. The try block at line 976 handles single package installation interactively
  2. The else: block at line 1047 is for batch installation when multiple packages are specified
  3. But there's no corresponding if statement - the code flow is broken

The fix should:

  1. Remove or properly integrate the orphaned else: block (lines 1047-1067)
  2. The batch installation logic (calling batch_install_packages) should either be:
    • Removed if it's not needed in the search command context
    • Or properly integrated with an if condition checking for multiple packages

Looking at the context, the search command at line 585 only handles a single query string, so the batch installation else block seems to be misplaced code that shouldn't be in the search command's handle_search_command function. This block likely belongs to an install command that wasn't fully merged.

The simplest fix is to remove lines 1047-1067 (the orphaned else: block) since:

  • The search command only searches for one query at a time
  • Batch installation logic is already in batch_install_packages() function
  • There are references to undefined variables like packages, source, and track in that block

Files to Modify

  • archpkg/cli.py - Fix the syntax error by removing the orphaned else block (lines 1047-1067)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 9, 2025 06:02
…xcept handler

Co-authored-by: AdmGenSameer <154604600+AdmGenSameer@users.noreply.github.com>
Co-authored-by: AdmGenSameer <154604600+AdmGenSameer@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix syntax error in archpkg cli.py Fix syntax error from orphaned else block in cli.py Dec 9, 2025
Copilot AI requested a review from AdmGenSameer December 9, 2025 06:08
@AdmGenSameer
AdmGenSameer marked this pull request as ready for review December 9, 2025 06:09
@AdmGenSameer
AdmGenSameer merged commit 86d750f into main Dec 9, 2025
@AdmGenSameer
AdmGenSameer deleted the copilot/fix-syntax-error-in-cli branch December 9, 2025 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants