From 9b58beeb8b3940547ae97c89eac354b316b5ee64 Mon Sep 17 00:00:00 2001 From: hemarina Date: Mon, 9 Mar 2026 16:54:08 -0700 Subject: [PATCH 1/2] add error suggestion yml rule and actions in error message --- cli/azd/pkg/errorhandler/pipeline_test.go | 11 +++++++++++ cli/azd/pkg/prompt/prompter.go | 3 ++- cli/azd/resources/error_suggestions.yaml | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cli/azd/pkg/errorhandler/pipeline_test.go b/cli/azd/pkg/errorhandler/pipeline_test.go index e736c1d7c95..86ca4fd6816 100644 --- a/cli/azd/pkg/errorhandler/pipeline_test.go +++ b/cli/azd/pkg/errorhandler/pipeline_test.go @@ -572,6 +572,17 @@ func TestPipeline_RBACErrors(t *testing.T) { } } +// --- Subscription error rule test --- +func TestPipeline_NoSubscriptionsFound(t *testing.T) { + pipeline := NewErrorHandlerPipeline(nil) + + err := errors.New("no subscriptions found") + result := pipeline.Process(context.Background(), err) + require.NotNil(t, result, "Should match 'no subscriptions found' pattern") + assert.Equal(t, "No Azure subscriptions were found for your account.", result.Message) + assert.Contains(t, result.Suggestion, "azd auth login --tenant-id") +} + func TestErrorSuggestionsYaml_IsValid(t *testing.T) { // Verify the embedded YAML can be parsed var config ErrorSuggestionsConfig diff --git a/cli/azd/pkg/prompt/prompter.go b/cli/azd/pkg/prompt/prompter.go index d6bc4589a77..7661e4f22da 100644 --- a/cli/azd/pkg/prompt/prompter.go +++ b/cli/azd/pkg/prompt/prompter.go @@ -78,7 +78,8 @@ func (p *DefaultPrompter) PromptSubscription(ctx context.Context, msg string) (s return "", errors.New(heredoc.Docf( `no subscriptions found. Ensure you have a subscription by visiting %s and search for Subscriptions in the search bar. - Once you have a subscription, run 'azd auth login' again to reload subscriptions.`, + Once you have a subscription, run 'azd auth login' again to reload subscriptions. + If you have multiple tenants, run 'azd auth login --tenant-id ' to specify your tenant.`, p.portalUrlBase, )) } diff --git a/cli/azd/resources/error_suggestions.yaml b/cli/azd/resources/error_suggestions.yaml index 6ea726a0dba..45d915f118e 100644 --- a/cli/azd/resources/error_suggestions.yaml +++ b/cli/azd/resources/error_suggestions.yaml @@ -382,6 +382,23 @@ rules: message: "The Azure authentication session may have expired." suggestion: "Run 'azd auth login' to refresh your credentials, then retry." + # ============================================================================ + # Subscription Errors + # ============================================================================ + + - patterns: + - "no subscriptions found" + message: "No Azure subscriptions were found for your account." + suggestion: > + Ensure you have an active subscription at https://portal.azure.com. + If you have multiple tenants, run 'azd auth login --tenant-id ' + to sign in to a specific tenant. Multi-factor authentication (MFA) may prevent + automatic access to all tenants — visit the Azure portal and switch to each tenant + to refresh your MFA sessions, then retry 'azd auth login'. + links: + - url: "https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login" + title: "azd auth login reference" + # ============================================================================ # Text Pattern Rules — Specific patterns first # These are fallbacks for errors without typed Go structs. From 5f1a77239b445e1d5a2d54a2a8ee6d9e5fba159c Mon Sep 17 00:00:00 2001 From: hemarina Date: Wed, 11 Mar 2026 17:31:25 -0700 Subject: [PATCH 2/2] address feedback --- cli/azd/pkg/errorhandler/pipeline_test.go | 2 +- cli/azd/pkg/prompt/prompter.go | 5 +++-- cli/azd/resources/error_suggestions.yaml | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/azd/pkg/errorhandler/pipeline_test.go b/cli/azd/pkg/errorhandler/pipeline_test.go index 86ca4fd6816..7bf712b5423 100644 --- a/cli/azd/pkg/errorhandler/pipeline_test.go +++ b/cli/azd/pkg/errorhandler/pipeline_test.go @@ -572,7 +572,6 @@ func TestPipeline_RBACErrors(t *testing.T) { } } -// --- Subscription error rule test --- func TestPipeline_NoSubscriptionsFound(t *testing.T) { pipeline := NewErrorHandlerPipeline(nil) @@ -581,6 +580,7 @@ func TestPipeline_NoSubscriptionsFound(t *testing.T) { require.NotNil(t, result, "Should match 'no subscriptions found' pattern") assert.Equal(t, "No Azure subscriptions were found for your account.", result.Message) assert.Contains(t, result.Suggestion, "azd auth login --tenant-id") + assert.NotEmpty(t, result.Links, "Should include documentation links") } func TestErrorSuggestionsYaml_IsValid(t *testing.T) { diff --git a/cli/azd/pkg/prompt/prompter.go b/cli/azd/pkg/prompt/prompter.go index 7661e4f22da..67721e70eed 100644 --- a/cli/azd/pkg/prompt/prompter.go +++ b/cli/azd/pkg/prompt/prompter.go @@ -75,11 +75,12 @@ func (p *DefaultPrompter) PromptSubscription(ctx context.Context, msg string) (s } if len(subscriptionOptions) == 0 { + // NOTE: Error text must contain "no subscriptions found" to match the + // pattern in error_suggestions.yaml. Update both if rewording. return "", errors.New(heredoc.Docf( `no subscriptions found. Ensure you have a subscription by visiting %s and search for Subscriptions in the search bar. - Once you have a subscription, run 'azd auth login' again to reload subscriptions. - If you have multiple tenants, run 'azd auth login --tenant-id ' to specify your tenant.`, + Once you have a subscription, run 'azd auth login' again to reload subscriptions.`, p.portalUrlBase, )) } diff --git a/cli/azd/resources/error_suggestions.yaml b/cli/azd/resources/error_suggestions.yaml index 45d915f118e..e746c1e1d9b 100644 --- a/cli/azd/resources/error_suggestions.yaml +++ b/cli/azd/resources/error_suggestions.yaml @@ -388,6 +388,7 @@ rules: - patterns: - "no subscriptions found" + - "no subscription found" message: "No Azure subscriptions were found for your account." suggestion: > Ensure you have an active subscription at https://portal.azure.com.