Throwing exception when service plan is not created#43
Throwing exception when service plan is not created#43LavanyaK235 wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves error handling when creating Azure App Service plans by extracting the creation logic into a separate testable method and adding explicit verification that the plan was successfully created. Previously, if plan creation failed silently (e.g., due to quota limits or permission issues), the setup would continue without detecting the problem.
Key Changes:
- Extracted App Service plan creation logic into
EnsureAppServicePlanExistsAsyncmethod with post-creation verification - Added comprehensive test coverage for various failure scenarios (quota limits, permission denied, silent failures)
- Added
InternalsVisibleToattribute to enable testing of internal methods
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Microsoft.Agents.A365.DevTools.Cli/Services/A365SetupRunner.cs |
Extracted inline App Service plan creation into new EnsureAppServicePlanExistsAsync method that verifies plan existence after creation and throws exception on failure |
src/Tests/Microsoft.Agents.A365.DevTools.Cli.Tests/Services/A365SetupRunnerTests.cs |
Added comprehensive test suite covering successful creation, existing plans, quota limit errors, permission errors, and silent failures |
src/Microsoft.Agents.A365.DevTools.Cli/Microsoft.Agents.A365.DevTools.Cli.csproj |
Added InternalsVisibleTo for test project to access internal method |
| await AzWarnAsync($"appservice plan create -g {resourceGroup} -n {planName} --sku {planSku} --is-linux --subscription {subscriptionId}", "Create App Service plan"); | ||
|
|
||
| // Verify the plan was created successfully | ||
| var verifyPlan = await _executor.ExecuteAsync("az", $"appservice plan show -g {resourceGroup} -n {planName} --subscription {subscriptionId}", captureOutput: true, suppressErrorLogging: true); | ||
| if (!verifyPlan.Success) | ||
| { | ||
| _logger.LogError("ERROR: App Service plan creation failed. The plan '{Plan}' does not exist.", planName); | ||
| throw new InvalidOperationException($"Failed to create App Service plan '{planName}'. This may be due to quota limits or insufficient permissions. Setup cannot continue."); |
There was a problem hiding this comment.
The error details from the failed App Service plan creation are lost when throwing the exception. Consider capturing the result from AzWarnAsync or directly calling _executor.ExecuteAsync to access result.StandardError, which would provide more specific error information (e.g., quota limits vs. permissions) to include in the exception message.
Throwing exception when service plan is not created