-
Notifications
You must be signed in to change notification settings - Fork 656
Add user-friendly error handling for aspire new
when directory contains existing files
#10496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user-friendly error handling for aspire new
when directory contains existing files
#10496
Conversation
Co-authored-by: mitchdenny <[email protected]>
…Runner Co-authored-by: mitchdenny <[email protected]>
aspire new
when directory contains existing files
…project creation conflicts - Remove ProjectAlreadyExistsException from DotNetCliRunner.NewProjectAsync - Add direct exit code 73 check in DotNetTemplateFactory.ApplyTemplateAsync with descriptive comment - Update unit test to verify exit code 73 is returned instead of expecting exception - All 112 CLI tests pass, maintaining full backward compatibility Co-authored-by: mitchdenny <[email protected]>
Here is a screenshot of the output that this code produces for reference: @copilot you can ignore this comment - no action is necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @davidfowl @maddymontaquila I think this one is ready to go in (also needs to be backported).
Co-authored-by: davidfowl <[email protected]>
Updated the error message to be more accurate - it now clarifies that the issue is specifically about conflicting files that would be overwritten, not just any existing files in the directory. See commit 76fe7af. |
/backport to release/9.4 |
Started backporting to release/9.4: https://github.com/dotnet/aspire/actions/runs/16383156860 |
Summary
Fixes #9685 by replacing the long, unfriendly error output from
dotnet new
with a clear, actionable message when users attempt to create a new Aspire project in a directory that already contains files.Problem
When running
aspire new
in a directory that already contains files from a previous project, the command would fail with exit code 73 and display a long, technical error message fromdotnet new
that mentioned the unsupported--force
option. This was confusing for users since the aspire CLI doesn't support the--force
flag.Before:
Solution
Added custom error handling that detects exit code 73 from
dotnet new
and displays a user-friendly message instead.After:
Changes Made
Core Implementation
ProjectAlreadyExistsException
: New custom exception inAspire.Cli.Exceptions
namespaceDotNetCliRunner.NewProjectAsync
: Modified to detect exit code 73 fromdotnet new
and throw the custom exception with reference to issue aspire new asks you to use --force on dotnet new if the folder already exists. #9685DotNetTemplateFactory.ApplyTemplateAsync
: Added try-catch block to handleProjectAlreadyExistsException
and display the user-friendly error messageResources
ProjectAlreadyExists
string inTemplatingStrings.resx
with the user-friendly messageTesting
NewCommandWithExitCode73ShowsUserFriendlyError
verifies the complete flow returns the correct exit codeNewProjectAsyncThrowsProjectAlreadyExistsExceptionOnExitCode73
verifiesDotNetCliRunner
throws the correct exception on exit code 73Technical Details
The implementation is surgical and minimal:
DotNetCliRunner.NewProjectAsync
checks ifdotnet new
returns exit code 73ProjectAlreadyExistsException
instead of returning the exit codeDotNetTemplateFactory.ApplyTemplateAsync
catches the exception and displays the friendly messageVerification
✅ Functionality verified: Confirmed
dotnet new
returns exit code 73 when attempting to create templates in directories with existing files✅ No regressions: All existing CLI functionality preserved
✅ Error handling: Custom exception properly thrown and caught
✅ User experience: Clear, actionable error message displayed
The change provides users with clear guidance on how to resolve the issue (remove or move existing files) without mentioning unsupported options.
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:
go.microsoft.com
If you need me to access, download, or install something from one of these locations, you can either:
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.