Skip to content

Conversation

Copy link
Contributor

Copilot AI commented May 22, 2025

Problem

When running the aspire new or aspire add commands without an internet connection, the CLI attempts to prompt the user to select from a list of available template versions or packages. Since no templates/packages are available offline, this results in an unhandled exception (System.InvalidOperationException: Cannot show an empty selection prompt).

Changes

This PR adds proper error handling for offline scenarios by:

  1. Adding an EmptyChoicesException class to handle cases with no available choices
  2. Modifying the InteractionService.PromptForSelectionAsync method to check if the choices collection is empty before attempting to prompt the user
  3. Updating command classes to:
    • Check for empty package collections
    • Throw meaningful exceptions with clear error messages
    • Catch and handle these exceptions appropriately

User Experience

When offline or when no templates/packages are found, the user will now receive clear error messages like:

No template versions were found. Please check your internet connection or NuGet source configuration.

No integration packages were found. Please check your internet connection or NuGet source configuration.

Testing

Added tests for:

  • Empty collection handling in InteractionService
  • Error handling for empty template/package lists in NewCommand and AddCommand

Fixes #9457.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dnceng.pkgs.visualstudio.com
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet build src/Aspire.Cli/Aspire.Cli.csproj (dns block)
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --filter FullyQualifiedName~InteractionServiceTests|FullyQualifiedName~AddCommand_EmptyPackageList|FullyQualifiedName~NewCommand_EmptyPackageList (dns block)
  • pkgs.dev.azure.com
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet build src/Aspire.Cli/Aspire.Cli.csproj (dns block)
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --filter FullyQualifiedName~InteractionServiceTests|FullyQualifiedName~AddCommand_EmptyPackageList|FullyQualifiedName~NewCommand_EmptyPackageList (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 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.

@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label May 22, 2025
Copilot AI changed the title [WIP] Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands May 22, 2025
Copilot AI requested a review from mitchdenny May 22, 2025 01:10
@mitchdenny mitchdenny marked this pull request as ready for review May 22, 2025 01:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds graceful handling of offline scenarios for aspire new and aspire add by throwing and catching a dedicated exception when no templates or packages are available.

  • Introduces EmptyChoicesException and guards prompts against empty collections
  • Updates InteractionService to throw on empty choices and enhances NewCommand/AddCommand with checks and catch blocks
  • Adds unit tests covering empty-choice scenarios in the interaction layer and the two commands

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/TestServices/TestInteractionService.cs test stub that throws EmptyChoicesException for empty prompts
tests/Aspire.Cli.Tests/Interaction/InteractionServiceTests.cs new test for PromptForSelectionAsync with no choices
tests/Aspire.Cli.Tests/Commands/NewCommandTests.cs new test for empty-template error handling in NewCommand
tests/Aspire.Cli.Tests/Commands/AddCommandTests.cs new test for empty-package error handling in AddCommand
src/Aspire.Cli/Interaction/InteractionService.cs added empty-check and throw in PromptForSelectionAsync
src/Aspire.Cli/Interaction/EmptyChoicesException.cs introduced EmptyChoicesException class
src/Aspire.Cli/Commands/NewCommand.cs added empty-list guard and catch in NewCommand
src/Aspire.Cli/Commands/AddCommand.cs added empty-list guard and catch in AddCommand

@mitchdenny
Copy link
Member

I think this is good to go.

@davidfowl davidfowl merged commit 3e3056e into main May 22, 2025
266 of 267 checks passed
@davidfowl davidfowl deleted the copilot/fix-9457 branch May 22, 2025 07:50
@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graceful error handling for offline scenarios in 'aspire new' and 'aspire add' commands

3 participants